Forum Moderators: open

Message Too Old, No Replies

Pattern Matching with Regular Expressions

The double quote

         

circuitjump

4:44 pm on Feb 4, 2002 (gmt 0)

10+ Year Member



Hi all,
I got a quick question.
What would be the best way to changing a sentence in JS that goes like so

"This is a "BIG"cat."

I want to change that to this
"This is a \"BIG\" cat."

Then I want to do
document.write quotes;

quotes being the variable I save all of this on.

I've been reading about search(), and replace() but dont know how to quite use them to do this trick.

Any suggestions?

txbakers

5:02 pm on Feb 4, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use the double quotes in your document write method, then change the outer quotes of the sentence to single quotes, leaving the escaped double quotes around the word BIG.

circuitjump

5:05 pm on Feb 4, 2002 (gmt 0)

10+ Year Member



Not quite getting what you mean there txbakers. Could I bother you to go a little more into what your saying?

Thanks

joshie76

6:37 pm on Feb 4, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Bit baffled at exactly what and why you're trying to do but (as the answer depends on where the string is coming from originally) I think txbakers is saying to try the following:

var test = 'This is a "BIG" cat';

Using the single quotes means you don't have to escape the double quotes.

FYI: The replace function works as follows:

var test = 'hello mr smith';
test = test.replace('smith','johnson');

This would result in "hello mr johnson"

Regular expressions are a whole different kettle of fish and much more complex. I shouldn't think you'll need them for what you're trying to do.

if you can let us know exactly where and why you need to do what you're doin' perhaps a code snippet, I'm sure one of us'll have the definitive answer.

Josh

circuitjump

7:23 pm on Feb 4, 2002 (gmt 0)

10+ Year Member



Hi all,

This is exactly what I'm trying to do. I posted this on the server-side area of the site. It has to do with server-side languages but ....... well, check it out it will tell you exactly what i'm trying to do.

[webmasterworld.com...]

Thank you all