Is there a way to regexp-quote strings in Node.js?

I want to create a regular expression that exactly matches the string foo, even if foo contains metacharacters. This is sometimes called RegExp.quote . Is there a way to do this in Node.js (or, more broadly, v8 / Chrome / WebKit / JavaScript)?

+6
source share
1 answer

npm install regexp-quote

 RegExp.quote = require('regexp-quote') // optional new RegExp(RegExp.quote(foo)) 
+17
source

Source: https://habr.com/ru/post/914478/


All Articles