A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-escaperegexp-method/ below:

Lodash _.escapeRegExp() Method - GeeksforGeeks

Lodash _.escapeRegExp() Method

Last Updated : 25 Oct, 2023

Lodash _.escapeRegExp() method is used to escape the Regular Expression special characters "^", "$", "", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in string.

Syntax:
_.escapeRegExp([string='']);
Parameters: Return Value:

This method returns the escaped string.

Example 1: In this example, we are getting the escape string by the use of the _.escapeRegExp() method.

JavaScript
const _ = require('lodash');

let str1 = _.escapeRegExp("/a/");
console.log(str1);

let str2 = _.escapeRegExp("\*?{}.");
console.log(str2);

Output:

/a/
\\*\\?\\{\\}\\.

Example 2: In this example, we are getting the escape string by the use of the _.escapeRegExp() method.

JavaScript
const _ = require('lodash');

let str1 = _.escapeRegExp("/geeks/");
console.log(str1);

let str2 = _.escapeRegExp("/(?<geeks>.)(?<for>.)(?<geeks>.)/");
console.log(str2);

let str3 = _.escapeRegExp("\*?????{}.");
console.log(str3);

Output:

/geeks/
/\(\?<geeks>\.\)\(\?<for>\.\)\(\?<geeks>\.\)/
\*\?\?\?\?\?\{\}\.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4