Suppose I have a regular expression with many alternatives, such as
"[a-z]+\\|[A-Z]+\\|[0-9]+"
and it has just matched some text. I'd then like to know which of the given alternatives caused the match.
Of course I can consult (match-string 0)
to check the matched string, but I have a much more complicated situation in mind where this may not be as easy as it looks. Would there be an automatic way to do this?
I thought of grouping the alternatives and numbering them, as in
"\\(?1:[a-z]+\\)+\\|\\(?2:[0-9]+\\)+\\|\\(?3:[A-Z]+\\)+"
and then searching for the apropriate n
making (match-string n)
non-nil, but I wonder if there is a better idea.