I'm not familiar with Proof General, but it looks as though exec
returns only a single match at a time. The results that you're seeing are:
"Zip or City & State"
— the complete matched substring.undefined
— the substring captured by the(\\s\\(Optional\\)|$)
capture-group. Or not captured, in this case, because that capture-group is inside a non-matching alternand.
To remove the latter, you can (presumably) change the (
to (?:
, marking it as a non-capturing group.
To retrieve subsequent matches, you likely need to call exec
multiple times.