Instead of using the /regex\d/g
syntax, you can construct a new RegExp object:
var replace = "regex\\d"; var re = new RegExp(replace,"g");
You can dynamically create regex objects this way. Then you will do:
"mystring1".replace(re, "newstring");
Related Posts:
- Javascript split regex question
- What is a good regular expression to match a URL? [duplicate]
- What is a good regular expression to match a URL? [duplicate]
- Is there a difference between /\s/g and /\s+/g?
- RegEx Ignore Case
- JavaScript replace/regex
- Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters
- Escaping Discord subset of markdown
- How to test valid UUID/GUID?
- Regular expression : match either of two conditions?
- RegExp in TypeScript
- Converting any string into camel case
- I want to remove double quotes from a String
- Regular expression for removing whitespaces
- Javascript Regular Expression Remove Spaces
- How can I extract a number from a string in JavaScript?
- Remove not alphanumeric characters from string
- Extract hostname name from string
- Difference between ?:, ?! and ?=
- Remove all special characters with RegExp
- How to count string occurrence in string?
- Regular Expression to reformat a US phone number in Javascript
- Jquery Value match Regex
- RegEx: How can I match all numbers greater than 49?
- Regular expression to validate US phone numbers?
- javascript includes() case insensitive
- RegEx for Javascript to allow only alphanumeric
- Check user logged in with JS
- Find object by id in an array of JavaScript objects
- Cannot set property InnerHTML of null [duplicate]
- How can I submit a form using JavaScript?
- How do I empty an array in JavaScript?
- JavaScript TypeError: Cannot read property ‘style’ of null
- JavaScript string newline character?
- How to create a GUID / UUID
- How does “/\s/g” replace spaces with other characters?
- What is the correct way to check for string equality in JavaScript?
- JavaScript TypeError: Cannot read property ‘style’ of null
- Number converted in 1e+30
- Static variables in JavaScript
- ReferenceError : window is not defined at object.
Node.js - Node.js Port 3000 already in use but it actually isn’t?
- Uncaught TypeError: $.post is not a function
- Unable to verify leaf signature
- XML Parsing Error: no root element found Location in Console FF
- TypeError: app.use() requires middleware functions
- Possible to extend types in Typescript?
- JavaScript enumerator?
- How to format numbers as currency strings
- Obtain form input fields using jQuery?
- Npm install cannot find module ‘semver’
- How to download a file with Node.js (without using third-party libraries)?
- Getting current date and time in JavaScript
- What is ViewChild in Angular2?
- Permutations in JavaScript?
- How do I remove documents using Node.js Mongoose?
- jQuery make global variable
- Mixed Content Page: requested an insecure stylesheet error
- How to do integer division in javascript (Getting division answer in int not float)?
- javascript unexpected identifier
- How to send email by using javascript or jquery
- Access to Image from origin ‘null’ has been blocked by CORS policy
- Read XML file using javascript
- Load Image from javascript
- Most efficient method to groupby on an array of objects
- Don’t make functions within a loop [duplicate]
- JavaScript post request like a form submit
- Set CSS property in JavaScript?
- how to write javascript code inside php
- javascript convert int to float
- Uncaught TypeError: Cannot read property ‘toLowerCase’ of undefined
- How do I convert a JavaScript forEach loop/function to CoffeeScript
- ZIP Code (US Postal Code) validation
- Is there a standard function to check for null, undefined, or blank variables in JavaScript?
- How to force JavaScript to deep copy a string?
- jQuery .animate() not working
- how to add inside a text box?
- is it posible to add anime.js in WordPress
- Is it possible to enqueue the Youtube API script or does it have to be inline?
- What type of template are WP media-modal’s templates?
- is_front_page() not working
- Gutenberg RichText
- Sending custom data with Media Frame Model
- Unwanted line break before
- Adding JavaScript to a WordPress website
- Multiple Conditional Controllers
- Adding javascript trigger to user role selection on the user-edit page
- Vue and wordpress.Bad Request ajax request
- How to add if lt IE9 conditional scripts to functions.php
- Looping over wordpress meta to create “ ‘s?
- How to include a JSON file on my page?
- Adding inline JavaScript after wp_enqueue_scripts
- Update media library attachments
- JavaScript Libraries in WordPress
- how to use nimble-API and Display data?
- Create new product with woocommerce REST API with javascript (clientside)?
- Combining results from WP-API using AngularJS
- dropdown does not work [closed]
- Anyway to disable the auto excerpt creation?
- How do I cycle a JS function in WordPress? [closed]