ctrl + k
On This Page
Functions
Regular Expression Utilities
The Regular Expression utilities provide functions for working with regular expressions and string patterns in JavaScript. These functions help in creating, escaping, and applying regular expressions efficiently.
Functions
escapeRegExp
Escapes special characters in a string for use in a regular expression.
This function escapes all special regex characters
[ ] { } ( ) / \ ^ $ . | ? * +
which is helpful when inserting a dynamic string into a regex like a user search query.
Parameters
Name | Type | Description |
---|---|---|
string | string | The string to escape |
Returns
A new string with all regular expression special characters escaped.
Example
escapeHTML
Escapes HTML special characters in a string.
Parameters
Name | Type | Description |
---|---|---|
string | string | The string to escape |
Returns
A new string with HTML special characters escaped.