I want to find /AA/ pattern in AA-AA-AA subject string. I need to get the matching string and the position (index) of the match.
/AA/
AA-AA-AA
I have loo
http://jsfiddle.net/mplungjan/MNXvQ/
I think this is easier to grasp
var str = "AAbAAcAAd" var re = /(AA)/gi; var t="",cnt=0; while ((result=re.exec(str))!=null) { document.write((cnt++)+":"+result[1]+"") }
re.lastIndex contains the positions each time