Declare the escape function at first
RegExp.escape = function(string) { return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') };And you can search special character like this code
var patern = '^^'; var regex = new RegExp(RegExp.escape(patern)); var text = 'Hello^^'; var match = text.match(regex));Try to type the input
Try to type the patern with special character
Matched text found:
Post a Comment