So I have this function that I created that replaces special characters that are inside of a string. The main intent was to replace those special characters that were inside of the BBCode tag ([code=any]my code that I want to show[/code]), but at the time it didn't really matter if it replaced the rest of the string outside of the BBcode tag. But now I'm having problems with it replacing HTML tags that are outside of the BBcode tag. So I was trying to come up with a solution for this, but no luck so far.
The goal is to replace the special characters that are inside of the:
[code=any]some code inside of here[/code]
Also should mention that when I say code=any meaning it can be anything. It could be HTML,CSS,PHP,JS [a-z-A-Z-0-9].
so more like
[code=[a-z-A-Z-0-9]<h1>some html insode of the bbcode to be replace</h1>[/code]
My current function is simple. Just some basic regular expression is needed:
replaceSpecial : function(str) {
str = str.replace(/&/g, "&");
str = str.replace(/>/g, ">");
str = str.replace(/</g, "<");
str = str.replace(/"/g, """);
str = str.replace(/'/g, "'");
return str;
}
But how would I go about rewriting that so that it will only replace text that is inside of the: [code=any]some code inside here[/code] and that's it. If anyone has a solution for this, that would be awesome.
Thanks for your time, Jon W