There is a string coming from input , you need to make a regular list (an analogue of the search), but if we allow + or \ to be entered in the field, there will be an error creating a regular expression through new RegExp, because it accepts not a string, but a pattern, how can you avoid it? so that when I enter any data into input , I have created a regular search for this string, and not a pattern that was processed by ReqExp ? and is this the right approach?
|
1 answer
Screen the special characters in the string and you get a valid regular schedule.
RegExp.escape= function(s) { return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); }; (C) https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
- one+1 for creating a regular expression using a regular expression - yar85
|
тк она принимает не строку , а паттернcontrary. line it takes javascript.ru/regExp - Lexx918