I'm performing a regular expression using the match() method on a string that es from the user and could contain anything, including $^'s etc.. so I need to escape those characters before this happens.
Is there a mon function in jQuery to do this, a well known javascript function or am I going to have to do it manually (with the chance I might miss something?)
I'm performing a regular expression using the match() method on a string that es from the user and could contain anything, including $^'s etc.. so I need to escape those characters before this happens.
Is there a mon function in jQuery to do this, a well known javascript function or am I going to have to do it manually (with the chance I might miss something?)
Share Improve this question edited Sep 25, 2012 at 20:41 Brian Webster 30.9k51 gold badges157 silver badges226 bronze badges asked Mar 15, 2011 at 0:07 John HuntJohn Hunt 4,0729 gold badges46 silver badges61 bronze badges 01 Answer
Reset to default 13Found a function here:
RegExp.escape = function(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}