I have problem with JavaScript Regular Expression. I have test it on this website and it’s working fine – http://www.pagecolumn.com/tool/regtest.htm .
var str = "Stalowa Wola;Nisko;Rzeszow";
var re = new RegExp("Stalowa Wola[a-zA-Z\W]*Rzeszow", "i");
var myArray = str.match(re);
console.log(myArray);
But when I trying to run this code on my website, it’s not working.Console return ‘null’ and I don’t know why. I noticed that when i remove ‘Rzeszow’ from RegExp it’s starts working.
You need to escape the backslash.
Alternatively use this notation:
The downside is that you must know the structure of the regex before runtime.
http://www.regular-expressions.info/javascript.html