Namespace: Strings:maskForRegEx

Strings:maskForRegEx

Source:

Methods

maskForRegEx(str) → {String}

Masks all regex special characters, to test or match a string using a regex, that contains characters used in regexes themselves.

Parameters:
Name Type Description
str String

the string to mask for use in a regexp

Source:
Returns:
the masked string
Type
String
Example
if( (new RegExp(`^${maskForRegEx(arbitraryString)}$')).test('abc') ){
  alert('are identical!');
}