omega
omega

Reputation: 43833

How to combine regex and string in javascript?

If I have this hardcoded regex

/^ *\d+(?:\.\d+)+ *Country/

How can I change it so that Country comes from a string variable, and another variable would be /^ *\d+(?:\.\d+)+ */, then somehow concatenate it so it becomes

/^ *\d+(?:\.\d+)+ *Country/

?

Thanks

Upvotes: 0

Views: 43

Answers (1)

Maksim
Maksim

Reputation: 521

Maybe this helps

 var re = new RegExp('^ *\\d+(?:\\.\\d+)+ *'+  country);

Upvotes: 2

Related Questions