quote:
Originally posted by macgyver08
I found a regular expression that will strip my string of every html tag...
code:
var stripped = htmlStr.replace(/(<([^>]+)>)/ig,"");
Well, I also want it to strip every thing between parentheses, square brackets, and replace " " with a space.
It would be really cool if you could explain how to do this as well, because the stuff in the above code after "replace" confuses me. I have no idea how that's working.
the replace function is using
Regular Expressions, in the format of /pattern/modifiers. In this example, everything between the "/"s are the characters to replace and the ig are the modifiers (in this case, i for case insensitive and g for global [replaces all instances, not just the first]).
So, you can modify everything between the /'s to strip whatever character you want.
As for replacing " " with a space, just use another replace function...
Javascript code:
var stripped = htmlStr.replace(/(<([^>]+)>)/ig,"");
stripped = stripped.replace(/ /g," ");