Originally Posted by massalexx is it possible to avoid using regExp constructor so we can have a single line like this: inStr = inStr.replace(oldWordArr[i]+"/(?![^(]*\))/ig", newWordArr[i]); I am not sure if "ig" is allowed to be placed in there. By short: No.
KOR Windows Forum Register as or Find a freelancer Offshore programming
You can't avoid the constructer, but you can write it in one line. Code: inStr = inStr.replace(new RegExp(oldWordArr[i]+"/(?![^(]*\))","ig"), newWordArr[i]); Or maybe slightly clearer. Code: inStr = inStr.replace((new RegExp(oldWordArr[i]+"/(?![^(]*\))","ig")), newWordArr[i]);
inStr = inStr.replace(new RegExp(oldWordArr[i]+"/(?![^(]*\))","ig"), newWordArr[i]);
inStr = inStr.replace((new RegExp(oldWordArr[i]+"/(?![^(]*\))","ig")), newWordArr[i]);
Great wit and madness are near allied, and fine a line their bounds divide.
There are currently 1 users browsing this thread. (0 members and 1 guests)
View Tag Cloud
Forum Rules
Bookmarks