I want to create a regexp that matches exactly the string foo, even if foo contains metacharacters. This is sometimes known as RegExp.quote
. Is there a way to do this in a Node.js environment (or, more broadly, v8/Chrome/WebKit/JavaScript)?
npm install regexp-quote
RegExp.quote = require('regexp-quote') // optional
new RegExp(RegExp.quote(foo))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With