javascript escape regex

Solutions on MaxInterview for javascript escape regex by the best coders in the world

showing results for - "javascript escape regex"
Asher
25 Aug 2016
1// Vanilla JS
2function escapeRegex(string) {
3  return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
4}
5
6// Or with npm: npm install escape-string-regexp
7const escapeRegex = require('escape-string-regexp');
8
9// Usage:
10const regex = new RegExp(escapeRegex('How much $ is that?'));
Ayoub
25 Aug 2016
1function escapeRegExp(input) {
2	const source = typeof input === 'string' || input instanceof String ? input : '';
3	return source.replace(/[-[/\]{}()*+?.,\\^$|#\s]/g, '\\$&');
4}
5
queries leading to this page
sanitize input in js with regexjavascript regex escape 5csjavascript escape string for regexregex to escape special characters javascriptmake regex with special characters javascriptjs re escape inputwhate are the escape character in javascript regexnodejs escape character regexdo you have to escape characters in regex javascriptregex which characters to escape javascriptjavascript escape regexnodejs user input for regex escape special charactersauto escape all regex characters javascriptregex javascript special charactersescaing charaters in regex javascriptjavascript regex escape 22 2f 27regexp jnode js matchjs escape all special charactershow to escape regex characters in javascriptescape for regex jsregex escape string nodejsjavascript regular expression escape 3fjavascript regular expression escaperegex for an escaped string javascriptjavascript convert string to regex escapejavascrtipt escape regexjavascript regex escapeescape regex string jsjavascript regex match escapejavascript regex escape sequenceescape regex characters javascriptp escape regex javascriptmatch regex jsjs regex match escape stringregex escape function javascriptjavascript custom regex with escape charactersjavascript escape regular expressionnew regexp dont escape 2bescape for 2b in javascript regexjavascript how to escape in regexescape character in js regexjavascript regex is it necessary to escape apostrophe 3fregex sanitize jsjavascript regex unnecessary escape characterjavascript regular expression match escape 3fspecial characters regex javascriptjavascript regex escape symbolsescape regex typescriptnodejs string for regex escape special charactersjs escape regex special characters in stringnode regex match escape characterregex js escapehow to escape in javascript regular expressionjavascript string escape regex characterswhat is escape 22 5c 22 in js regexregular expression special characters javascriptescape character regex jsescape backslash javascript regexjs escape regexjavascript regex escape characters listjavascript escape to regexregex escape plus jsjs escape regex charactersescape characters js with regexescape regex javascriptjavascript escape quotes regexjavascript escape special characters regex 7e javascript escape regexjavascript regex exscapeescape regular expression javascriptescape regex jsregex escape string javascriptjs regex escape 24javascript regex for special characters examplehow to use special characters in javascript regexescape 3c 3e in regex javascriptstring to regex patternescape all special characters javascriptjavascript unescape to regexjavascript regexp literal asteriskjavascript string replace escape tokenjs string escape for regexescape an entire string regex javascriptjavascript regex escape 2ftypescript regexp string with excaped 2fregex variable scape javascriptregex escape character string in jsjavascript escape character in regexjavascript reg ex escape chaescape characters for regex javascriptwhat to escape in js regexregex change javascript string escape charactersjs new regexp escape quotesignore all special chcaracters in string javascriptregex javascript escape charactersescape 2a in regex javascriptescape string regexp nodejshow to escape characters regex nodejsjavascript regex to escape special charactersescape character regex javascriptjs regex special characterjavascript escape characters regexregex match in jsescape character javascript regexjs regex escape 3cescaping regex jsjs escape string for regexfunction escape regex characters 28str 29 7b return str replace 28 2f 5b 2a 2b 3f 5e 24 7b 7d 28 29 7c 5b 5c 5d 5c 5c 5d 2fg 2c 27 5c 5c 24 26 27 29 3b 7dregex sanitize input javascriptjs escape regexhow to escape regex javascriptregexp escape jsjavascript construct regexp with string escaperegexp escape javascriptjs escape regex stringregex looking for special characters jshow to regex escape javascriptregular expression escape characters javascriptregex escape word javascriptescape in regex javascriptjavascript escape text for regex searchjs auto escape regexregex escape 2b sign javascriptregex to remove escape characters javascript escape character in regex javascriptjavascript escape regex special charactersregular expressions and escape sequences javascript 7e javascript escape regexpescape regex for javascriptjavascript special characters regexjs regex escape ampersndjs user input regexp escapejavascript regex escape charactersspecial characters regex jsjavascript regexp escapejavascript regular expression escape 22js regex escape special characterjavascript escape regex patternhow to escape in javascript regexjs make a string regex friendlyjs regexp escaped characterescape in regex javascriptescape character in javascript regexkeep escape characters regex javascriptjavascript regex escape characterjavascirpt escape regex 5c to 5c 5cregex escape characters javascriptescape regex characters in string javascriptjs new regexp escapejavascript escape character regexjavascript escape for regexescape characters regex javascripthow to escape special characters in javascript regexnode escape character regexjs regex escape charactersjavascript new regexp escape special charactersjavascript escape string regexcharacter escape regex jsjs apply regex to stringescape 2f in regex replace javascriptjavascro regex escpae javascript escape all special charactershow to escape regex expressions in expressescape text into regex nodejsjavascript regexp escape 5cjs escape string to be used as regexpregex escape javascriptjs replace regex patterns for escapingstring to regexjavascript regex escape special charactersregex special characters javascript js regex insert escape characterstypesctipr escape string to regexregex for special characters javascriptjavascript string escape regexhow to regex js escapeescape value to regex javascriptregex characters to escape javascriptjs regex escapejavascript regular expression to escape 24 signstring escape javascript regexescape regex javascript scriptspecial characters regex in javascriptjavascript escape regex