I want to remove
- the entire text including curly braces
- the outer braces, but not the text within [[ and ]] only
[[Have to keep this text]] this {{ remove this junk }} and this.
I implemented the above and it is working at : http://jsfiddle.net/DMGdG/
I used this : https://raw.github.com/cowboy/jquery-replacetext/master/jquery.ba-replacetext.min.js
but in my server(127.0.0.1) the same code is not doing the trick, there i tried both the ways
str.replace(regex, charecter)
and the one mentioned at jsfiddle.
My queries:
- is my regex combo correct, if not please suggest, what is wrong.
- Please don’t think of any server error at its simply a main.js
jstr.replace("/\s*\{{.*?\}}\s*/g", " "); // for removing curly braces and text within.
jstr.replace("/[\[(.)\]]/g", ""); // to replace the square braces.
index.html has only a <p> Sample Text(as shown above)</p>
Instead of this:
Try this:
The addition of the question mark makes the matched pattern non-greedy — that is, it will match the very next
}}it encounters, rather the the very last one.Edit: You’ve stated this doesn’t work for you. Perhaps omitting the replaceText plug-in and using plain old
replace()instead will help:Again, it seems to work in your fiddle when edited as above. Perhaps the problem is with the plug-in.