Jump to content

[SOLVED] replacing <


rarebit

Recommended Posts

Hi i'm stuck on how to make this one work?

<script type='text/javascript'>
var search = new Array(/\076:O/ig, /\x3e:O/ig, /\>:O/ig);
var replace = new Array('XYZ','xyz', 'abc');
var s = "Hello Mr. >!";
s.replace(search[0],replace[0]);
s.replace(search[1],replace[1]);
s.replace(search[2],replace[2]);
document.write(s);
</script>

Link to comment
Share on other sites

Try this:

 

<script type='text/javascript'>
var search = new Array(/\076:O/ig, /\x3e:O/ig, /\>:O/ig);
var replace = new Array('XYZ','xyz', 'abc');
var s = "Hello Mr. >!";
s = s.replace(search[0],replace[0]);
s = s.replace(search[1],replace[1]);
s = s.replace(search[2],replace[2]);
document.write(s);
</script>

 

The replace() method returns the result... it does not apply it to the string automatically.

Link to comment
Share on other sites

Boo Hoo!

 

mmm, that's how I have it in the production code, hadn't noticed here, but for some reason it works in the test but not the production:

search = new Array(
	/\[b\](.*?)\[\/b\]/ig,
	/\[i\](.*?)\[\/i\]/ig,
	/\[u\](.*?)\[\/u\]/ig,
	/\[h1\](.*?)\[\/h1\]/ig,
	/\[h2\](.*?)\[\/h2\]/ig,
	/\[h3\](.*?)\[\/h3\]/ig,
	/\[h4\](.*?)\[\/h4\]/ig,
	/\[sub\](.*?)\[\/sub\]/ig,
	/\[sup\](.*?)\[\/sup\]/ig,
	/\[tt\](.*?)\[\/tt\]/ig,
	/\[s\](.*?)\[\/s\]/ig,
	/\[em\](.*?)\[\/em\]/ig,
	/\[strong\](.*?)\[\/strong\]/ig,
	/\[samp\](.*?)\[\/samp\]/ig,
	/\[kbd\](.*?)\[\/kbd\]/ig,
	/\[code\](.*?)\[\/code\]/ig,
	/\[code=(.*?)\]

 

All the escapism is because it's dumped out by php, and i've tried extra escaping on the backslash...

 

Cheers

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.