This is my code: mytext = mytext.replace(/(\[\[(.+)\]\])/gi,"(<script src='http://www.mysite.com/myscript?module=mymodule\&myvar=$2\&Output=JS'>)"); PHP: Despite escaping the &'s, the script doesn't replace the text [[ADSF]]. Instead the end result is just "(" without anything behind it. Does anyone know why this isn't working? Help would be enormously appreciated!
You script does return the result. [[ADSF]] is replaced to If you only want to replace the text in brackets, here is the code
nicely done, +rep (did not occur to me that the callback for .repalce could be an argumented relative function, that's brilliant!!! - makes total sense though)
Thanks for the reply! And that is quite brilliant with regards to replacing the text within the brackets- I didn't realize you could do that either... However, I actually do want to replace the brackets and everything. The problem is that when I use the above code from my first post, it doesn't work. I can have the [[ASDF]] and it errors out showing just the opening "(" with nothing following it. But, when I hard code the same script code with "ASDF" instead of the "$2" it works just fine. Then, if I change the script code to a link "<a href="$2">$2</a>", for example, it correctly creates the link. This leads me to believe that the $2 is working, the script is working, but the <script> created by the replace function isn't working for some reason (even though it should). Do you guys see any reason why this wouldn't be working? Escaped characters or anything that I'm missing? Thanks again!
Upon further investigation, the "&" is being replaced by "&" and is causing the problem. I tried escaping it with "\", using "&" in the code, using "%26" in the code, using "\u206" in the code, using CDATA, placing it in an external javascript, and all to no avail. Does anyone know how to keep the "&" in the URL in this case???