I have a working reg exp:
var re = /([^\wåäö]*?)([\wåäö]+)([^\wåäö&]?|$)|.+/ig;
When I replace it with this one it does not work any more:
var re = new RegExp("([^\wåäö]*?)([\wåäö]+)([^\wåäö&]?|$)|.+", "ig");
Should not these two be the same?
You should escape the
\using\\. When you type, for instance,\winside a regular expression literal (/\w/), it follows the regular expression syntax (which allowwafter a\). When you do the same thing inside a string, it follows the string syntax, which does not allow it. So, you shoud instead write"\\w"to achieve the same effect (in other words, the RegExp’ssourcewill be\w).