How to use 'javascript regex with variable' in JavaScript

Every line of 'javascript regex with variable' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
6function makeVariableRE(variableName) {
7 const reString = '\\$(' + variableName.replace(escapeRE, '\\$&') + ')\\b(\\[(.*?)\\])?';
8 return new RegExp(reString, 'g');

Related snippets