Variables in regexp

Enusiaacachaw

New Member
I have a regexp:\[code\]if (/(Name|Surname|City|Dog)/.test(names)) { alert('true');}\[/code\]I would like to use variables instead and pass it to this regexp, like:\[code\]$name = 'Name';$surname = 'Surname';$city = 'City';$dog = 'Dog';if (/($name|$surname|$city|$dog)/.test(names)) { alert('true');}\[/code\]This code doesn't work. What is the corrent one for this purpose?I would like to know how it can be done using regexp.
 
Top