Possible Duplicate:
Regex exec only returning first match
"a1b2c3d".replace(/[0-9]/g,"x")
returns “axbxdxd” as expected.
/[0-9]/g.exec("a1b2c3d")
however only returns an array containing one item: [“1”]. Shouldn’t it return all matches?
Thanks in advance!
No. You need to call
execmultiple times:Edit: The Mozilla Developer Network page on
exechas much more to say about this function. That’s where I got the example and modified it for your question.Edit 2: I’ve changed the above code so it isn’t actually an infinite loop. 🙂