showing results for - "pass variable to regrex literal notation javascript"
Andrés
28 Sep 2017
1// CREATE A REGEXP object
2var replace = "regex";
3var re = new RegExp(replace,"g");
4//then use
5"mystring".replace(re, "newstring")
Jane
18 May 2018
1// If you want to get ALL occurrences (g), be case insensitive (i), and use boundaries so that it isn't a word within another word (\\b):
2
3re = new RegExp(`\\b${replaceThis}\\b`, 'gi');
4
5// example:
6
7let inputString = "I'm John, or johnny, but I prefer john.";
8let replaceThis = "John";
9let re = new RegExp(`\\b${replaceThis}\\b`, 'gi');
10console.log(inputString.replace(re, "Jack")); // I'm Jack, or johnny, but I prefer Jack.
11
queries leading to this page
regex variablehow to add variable in regular expression javascriptregex use variable in javascriptuse variable in regex pattern javascript execvariables in regex javascriptjavascript regexp variablespass dynamic regex value in new regexphow to give variable inside regex pattern javascriptuse variable in regex javasciprtuse variable in regex exp javascripthow to insert a variable into replace jshow to but a varivable string inside regexjs reg variablevariables inside regexjavascript regex with variable withuse variable in regex jsregex variable 2f 2fadd variable in regex jsjavascript add variable into regexuse a variable in regex javascriptpass variable to regex javascriptvariables in regexp javascripthow to create regex with variable javascritjs create regex from variablepass a variable into regexuse a variable in a regex javascripthow to use variable value in regex javascriptvariable in reg jswhy javascript regex in variableadd variable to regex javascriptadd variable regex jsadd a variable in regex replaceusing variable in regexreplace regex variable jsjs variable in regex replaceuse variable in regexp javascriptjs regexp variable in patternjs regex and varhow to write variable name in regex in javascript 3fjs regex from string variablejs regex in if to varregular expression as a variableregex with variables javascripthow to create regex with variable jsregex variable javascriptjavascript variable regexuse a variable in regexregex set variable javascriptusing variable in regular expression javascriptuse variable in regular expression in jshow to use variable in regex jshow to turn variable intro regex jsjavascript use variable in regexjs add variable to regexhow to use regex on a variablepass variables in to regexvariable inside regular expresionnew regex with variablejavascript regex variableuse var in regezhow to use a string variable in a regual expression javascripthow to pass a variable in a regular expression javascriptusing variables in regex javascriptjavascript pass variable to regexjavascript variable in regechave variable value inside regexnode make regex from string variablejs var in regexjavascript varaibe in regexhjavascript regexp use variablejs new regexp with variablevariable in regex pattern javascriptregexp with variable jsnode regex with variableregex in variable javascriptjavascript regex in variablejavascript regex from variablevariable regex patternprovide variable in regex in jsjs use variable in regexput variable in regex javascriptregex javascript variableget script variable in javascript via regexvariable regex javascriptput js variable in regexregex for javascript variable name how to put variable in regez javascriptfunction regexvar 28 29regex 24 variablehow to pass variable in regexp substring javascript variable regular expressionjavascript variable in regex pattern replace javascript use varibalevariables in regexregexp with variable string in jsjs varibales inside regexesjavascript use va in regexvariable in regular expression jsregex panrams javascritregular expression with variable javascriptnode js regex with variablereference variable in regexusing variables with regex javascriptregular expression match variable literallyregex javascript variablesvariable in javascript regexhow to work with variables in regex javascriptpassing variable as regex javascriptregex variable value javascriptadd variable in regex javascirptvariable in a regex jsregex pattern with variablehow to add variable in regular expression 2f 2f in javascriptjavascript create regex from string variablejs put variable inside regexuse regex with var jsjavascript regular expression with variableregex variable meaningregexp variableregex variable is constant or let in jsjavascript use variable regexnew regexp javascript variablehow to use variable in regex javascriptusing javascript variables in regex expressionjs regex using variableusing variables in regex pattern javascriptjs regex with variable in patternregex with variable in javascripthow to put variable between regexcreate regex with variable javascripthow do you use a variable in a regular expressionjs regex with variablevaraible in regexjavascript regex with variable in patternvariable inside regex jsvarible in regex jsjavascript add variable to regex patternvariable in regexpadd variable in regex javascripthow to define regex as variableregex from variable javascriptjs regex to variablejavascript regex match variablejavascript using variables in regexhow to use variables in regex jsuse regex in javascript variablejavascript regular expression use variablehow to write variable in regex javascriptusing variables in regex jshow to pass variable in regex javascriptjs regex variable patternregex string with variables javascripthow to include variable in regexuse variable in a regexnew regex js with variablehow to use variable inside regex expression in javascripthow to add variable in replace javascriptjs interplate variable in regexuse variable value in regexp javascriptvariable in a regexhow to variable pass in regex javascripthow to pass variable to regex javascriptget variable javascritp regexjs variable in regechow to replace varialbe in expression jsjavascript compose regexregex use variable name javascriptstring variable in regex jsuse variable in regex javastriptjavascript regex variablesjavascript regex include variableregex with variablehow to regex variables jsjavascript regex into variablehow to form a regex in javascript variableregex as variable javascripthow to declare variable in regular expression javascriptjs regex how to put variable in patternvariabel in regex jsjs regex use variablecan i use variables inside regex javascriptadd a variable in regex javascriptdefine variable in regexjavascript regular expression variable in patternregexp javascript literal notation variablejs variable in regexhow to put variable in regex javascript 2f 2fvariable in js regexadd variable to regex jsjs include variable in regexpass a variable to a regexjavascript use variables in regexjavascript variable in regex matchwrite a variable in javascript in regular expressiondefining regex in varjavascript construct regex using variablepass a varaiable as a regexhow to use variable in regular expression jsjavascript variable in regular expressionhow to use variable in javascript regular expressionuse a paramater in regex jscan i pass a variable to a regex javascriptjavascript new regexp from variablejavascript regex from string variableregex from a variable jscreate regular expression javascript using variablesjavascript variable in regexvariable in regular expression javascripthow to put a variable string in a regex javascriptvariables regex javascriptuse variable in regexregex variable name javascriptuse parameters in regexregex js variablepass variable to regrex literal notation javascriptpass regex expressin as variableusing a variable in a regex javascriptadding variable to regular expressing javascriptjs var inside regex 24regex with variableregex pattern variable javascriptcan you pass a variable to regexhow to create a regex using variable javascriptjs regexp with variableshow to write a variable in regex javascriptjavascript arguments in regexregex with javascript variablees6 regexp with variablehow to use variable in regex patternhwo to add a variable inside regex expression jsjs variable in regular expressionhow to make a regex with variable javascripthow i use a variable in regexset variable as regexjs regular expression with variablejavascript use variable in regular expressionhow to add a variable to regexp in javascriptuse variables in regex javascriptjavascript regex add variablevariable as regex jshow to use varialbles in regexregex variablesjavascript regular expression use value in variableput a variable in regexuse variable in regex pattern javascriptinclude variable in regex javascriptregex javascript with variableusing variable within regexregex 2fstring 2fi js use variablestring variable as regex jsjavascript regext variablepass variable in js regular expressionvariable with regex javascriptjs make a regex with a variablejs regex with varhow to put variable in regex javascripthow to create regex variable javascriptregex use varaible javascripthow to use variable in regex pattern javascripthow to use variables inside regular expressionn 2f 2f javascriptjavascript assign regex to variableregex javascript get variablesjs regex and varijs define a regex variablenodejs use variables in regexpass param to regex jsjavascript how to make a regular expression variabledynamoc regex jsadd regex to var in jsusing a variable in regexjs use variable in regex patternusing a variable with regexregex javascript use variablejs pass variable to regexadd variable to javascript regexbuilding regex using variablesjavascript use variable in regex replace 2fvariable 2f in regular expression in javascriptpass variable in regex javascripthow to search for a variable with javascript regular expressionregex with parameter javascriptpass var to reg exnodejs add regexp on a variableargument in regex javascriptvariable into regex javascripthow to add a variable in regex b javascriptjavascript replace pattern variablejavascript regex variable in patternusing variable in regex jsassign regex to variable javascripthow declare variable in regex javascriptjavascript variable name regexwhat is var regex 3djavascript regex pattern with variableregex variable jstype variable in regex javascriptuse a variable in regex noderegex var jsnode regular expression add variableput regex in stringjavascript variable in regexphow to use variable in regexjavascript create regex pattern from string variablejavascript variable as regexhow to put a variable in a regex javascriptjavascript add variable to regexassign regex in variable javascriptjavascript regexp with variablesregiular expression define variableuse variable in javascript regexhow to pass a variable in as regexregex jwith variables javascriptvariable in regexp javascriptjs give a variable in regexjacvascript regex to variablejavascript regexp variablejavascript using a variable in regexjs regex add variablejs regex as variableexpresiones regulares javascriptjavascript regexp constructor with variableregular expressions js regex for variableshow to use variable in a regexuse a variable like regexjs regex variable in patternjavascript replace with variablepass variable into regex javascriptjs build regex from variablehow to add variable in regular expression create regex with variable strings javascriptjs variables inside regexregexp variable jspass variable to regular expression javascriptuse varaible in regex statment javascriptassign regular expression to variable javascriptput variable in regexvar in regex jsjavascript variable inside regexput variables in regexp patternhow to pass a variable into regex javascriptjavascript create regex from variableregexp string with variable jsjavascript regex user variablejs variable inside regexhow to make regex out of variable create reg ex using variable jsregex from variable jsregex with a variable jsvariable regexuse variable in regex javascriptjs new regexp variableuse a variable inside a regex javascriptjava script variable regular expressionreplace regex variable javascriptjavascript how to use variable in regexjavascript regex with variablehow to write variables in regex javascriptput variable inside regex jsregex using variable javascripthow to pass a variable inside a regexhow to store regex in variable javascriptvariable in regexuse vartible in regexjs make regex with varablejavascript adding variable inside regexhow to use a variable in regex javascriptjavascript put a variable in a regexjavascript regex pass variablecan we use a variable inside regexvariable regex jsjs regex from variablees6 cant put variables inside regexvariables in javascript regexregex of a variableregext variable javascirptuse variable for regular expression javascriptjs variable in regex patternregex with variable suse variable inside regexcan you use variable in regex javascriptusing variables in regexjs variable regexcreate a regex expression from a variable javascriptregular expression javascript parameterjs use variable inside regexjavascript replace regex variablehow to make regex variable javascriptuse variable in regular expression javascriptregex javascript using variablejs regex with variablesjavascript how to add variables in regexpretinsmake regex with variablejavascript regular expression variablejs replace regex variaturn variable into regex javascripthow to call a variable in regexhow to put a variable into a regex in jshow to use variable in rehexvariable in regex expjs use var in regexjs regex as a variableusing a variable in regex jsjs put variable in regexhow to put regex element in variable javascriptvariables in regex jsuse variables in regexhow to use variables in regex javascriptvariable inside regex javascripthow to get a string variable in regular expressionadd variable inside regex in javascriptusing variables in javascript regexvariable inside a regexvariable in js regexpspecify a value of regex from a variable in javascripthow to use a variable in a regular expression javascriptregex for variable jsuse variable inside regex javascriptregex use variableuse variable in regexpcreate regex variable javascriptjs regex variablejavascript regex using variableregexp javascript with variable in patternregex in javascript variablejs use variables in regexhow to include variable in regex in jsjs variable within regexpjs variables in regexhow to call variable instide regex javascriptjs set regex to variablehow to put a variable in regexwork with regex with js variavleregex replace variable javascripthow to assign regex to variable javascriptput a variable in regex jsadd var in regex jsregex with variable javascriptput a variable in a regex jsstore regex in variable javascripthow to pass variable in regexvariable in regex javascriptusing variable in js regexhow to get and use variable regexregex with variable jshow to include variable inside regex typescriptnew regexp with variableregex js using variableregexp with variables javascriptregex variable in patternvariable in regex jspass variable to regrex literal notation javascript