I want to match all occurrence in string.
Example:
pc+pc2/pc2+pc2*rr+pd
I want to check how many matched of pc2
value and regular expression is before and after special character
exists.
var str = "pc+pc2/pc2+pc2*rr+pd";
var res = str.match(new RegExp("([\\W])pc2([\\W])",'g'));
But I got only +pc2/
and +pc2*
and /pc2+
not get in this.
Problem is in first match /
is removed. So after that, it is starting to check from pc2+pc2*rr+pd
. That's why /pc2+
value does not get in the match.
How do I solve this problem?