rarebit Posted December 3, 2008 Share Posted December 3, 2008 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> Quote Link to comment Share on other sites More sharing options...
jwilliam Posted December 3, 2008 Share Posted December 3, 2008 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. Quote Link to comment Share on other sites More sharing options...
rarebit Posted December 3, 2008 Author Share Posted December 3, 2008 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 Quote Link to comment Share on other sites More sharing options...
rarebit Posted December 6, 2008 Author Share Posted December 6, 2008 Yep, I was pre-parsing, so I needed to also check for parsed elements: "/>:O/is", Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.