js> x "blah blah blah line: 2, blah blah blah line: 3, blah blah line: 4, blah blah" js> /line: (\d+),/g.exec(x); ["line: 2,", "2"]
No matter what I tried, this always gave me the first match, and no more. Luckily, Gavin had the answer: exec() is meant to be called in a loop, and position info is cached. It's about the least obvious API choice I can imagine for doing this, but here you are:
js> var r=/line: (\d+),/g; while (m=r.exec("blah blah blah line: 2, blah blah blah line: 3, blah blah line: 4, blah blah")) print(m); line: 2,,2 line: 3,,3 line: 4,,4
Now you know, and I'll have something to search for on Google next time I have to relearn this!