how to use the escaperegexp function from the lodash library in typescript

To use escapeRegExp function from Lodash in TypeScript, you should first install the Lodash library:

index.ts
npm install lodash
19 chars
2 lines

Then, you can import the escapeRegExp function and use it in your TypeScript code as shown below:

index.ts
import * as _ from 'lodash';

const myString = 'Hello World.';
const myEscapedString = _.escapeRegExp(myString);
console.log(myEscapedString); // Output: Hello\ World\.
169 chars
6 lines

Note that _.escapeRegExp takes a string argument and returns an escaped version of the string that can be used as a pattern in a regular expression.

gistlibby LogSnag