in reply to Re^5: Regex Optional capture doesn't (updated)
in thread Regex Optional capture doesn't
"single regex" is relative in Perl since you can include Perl-code investigating a sub-match
Does it must be a single regex, or is it just academic curiosity?
you need a positive condition which allows to stop the non-greedy only if you have a match or you reached the end.
DB<113> print join "|",'a<b1<b2' =~ /(a).+?(?:(c.)|$)/ a| DB<114> print join "|",'a<b1<c2' =~ /(a).+?(?:(c.)|$)/ a|c2 DB<115> print join "|",'a<c1<c2' =~ /(a).+?(?:(c.)|$)/ a|c1
Try to apply this technique.
HTH
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Regex Optional capture doesn't (updated)
by NetWallah (Canon) on Oct 05, 2017 at 17:57 UTC | |
by LanX (Saint) on Oct 05, 2017 at 18:07 UTC | |
by NetWallah (Canon) on Oct 05, 2017 at 18:33 UTC |