1 2 3 4 5 6 7 8 9
function f(str) { for (var i=0; i<10; i++) { arr = /foo(ba(r))?/.exec(str); var x = arr[0] + " " + arr[1] + " " + arr[2]; } } f("foobar"); f("foo");