Lodash _.escapeRegExp() Method

The _.escapeRegExp() method is used to escape the Regular Expression special characters “^”, “$”, “”, “.”, “*”, “+”, “?”, “(“, “)”, “[“, “]”, “{“, “}”, and “|” in string.
Syntax:
_.escapeRegExp([string=''])
Parameters: This method accepts single parameter as mentioned above and described below:
- string: This parameter holds the string to escape.
Return Value: This method returns the escaped string.
Example 1:
Javascript
| const _ = require('lodash');   varstr1 = _.escapeRegExp("/a/"); console.log(str1);  varstr2 = _.escapeRegExp("\*?{}."); console.log(str2); | 
Output:
"/a/"
"\\*\\?\\{\\}\\."
Example 2:
Javascript
| const _ = require('lodash');   varstr1 = _.escapeRegExp("/zambiatek/"); console.log(str1);  varstr2 = _.escapeRegExp("/(?<zambiatek>.)(?<for>.)(?<zambiatek>.)/"); console.log(str2);  varstr3 = _.escapeRegExp("\*?????{}."); console.log(str3); | 
Output:
"/zambiatek/"
"/\\(\\?<zambiatek>\\.\\)\\(\\?<for>\\.\\)\\(\\?<zambiatek>\\.\\)/"
"\\*\\?\\?\\?\\?\\?\\{\\}\\."
 
				 
					


