quoteRegExp()

Turn any string into a regular expression that matches the exact string without worrying about encoding the metacharacters yourself.

This function is valid in v2.0.0 to v2.24.3. This function has been downloaded 64 times.

Parameters

{string} str
The string that should be modified so that any characters that would normally serve as metacharacters in a regular expression will be escaped.
{boolean|string=} flagsOrMakeRegExp Optional, Default:false
If not specified or if false, it will cause just the escaped version of str to be returned. If true, it will be as if the empty string was passed in. A string represents the flags to be set in the returned regular expression.

Returns

{RegExp|string}
If flagsOrMakeRegExp is true a regular expression without flags will be returned. If flagsOrMakeRegExp is a non-empty string, a regular expression with the specified characters representing the corresponding flags will be returned. In all other cases just the escaped string that can be used as a regular expression will be returned.

Requiring Functions

This function is directly required by the following functions:

  • around()
    Gets the substrings around a specific target.
  • dice()
    Dices up a string splitting it on the passed in delimiter and placing the results in an array while making sure that the empty string is converted to an empty array.
  • replace()
    Replace targeted substrings with new strings.
  • trimLeft()
    Removes all whitespace characters or the specified characters from the beginning of a string.
  • trimRight()
    Removes all whitespace characters or the specified characters from the end of a string.