simplify escapeRegExp regexp
This commit is contained in:
parent
56432a67bc
commit
c5fdc1ab39
1 changed files with 2 additions and 2 deletions
|
@ -4,10 +4,10 @@ Ox.escapeRegExp <f> Escapes a string for use in a regular expression
|
|||
str <s> String
|
||||
> Ox.escapeRegExp('foo.com/bar?baz')
|
||||
'foo\\.com\\/bar\\?baz'
|
||||
> new RegExp(Ox.escapeRegExp('foo.com/bar?baz')).test('foo.com/bar?baz')
|
||||
> new RegExp(Ox.escapeRegExp('/\\^$*+?.-|(){}[]')).test('/\\^$*+?.-|(){}[]')
|
||||
true
|
||||
@*/
|
||||
// see https://developer.mozilla.org/en/JavaScript/Guide/Regular_Expressions
|
||||
Ox.escapeRegExp = function(string) {
|
||||
return (string + '').replace(/([\/\\\^\$\*\+\?\.\-\|\(\)\{\}\[\]])/g, '\\$1');
|
||||
return (string + '').replace(/([\/\\^$*+?.\-|(){}[\]])/g, '\\$1')
|
||||
};
|
Loading…
Reference in a new issue