in reply to Re: How to know that a regexp matched, and get its capture groups?
in thread How to know that a regexp matched, and get its capture groups?
> I'm confused...
I need to find the first regexp that is stored in @syntax that matches, and discard the rest. When one matches, I need the capture groups, if any.
But I'll take the other answer, that a regexp returns true even without capture groups. I could not quickly find any mention of return values in either perlre or perlsyn, both rather hefty pages, before asking. Was probably looking in the wrong place anyway... Ah, yes, I found it in perlop now:
Matching in list context If the "/g" option is not used, "m//" in list context returns a list consisting of the subexpressions matched by the parentheses in the pattern, that is, ($1, $2, $3...) (Note that here $1 etc. are also set). When there are no parentheses in the pattern, the return value is the list "(1)" for success. With or without parentheses, an empty list is returned upon failure.
I didn't expect this many answers, to be honest...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: How to know that a regexp matched, and get its capture groups?
by LanX (Saint) on Jan 10, 2023 at 16:03 UTC | |
by Anonymous Monk on Jan 10, 2023 at 17:48 UTC |