http://www.perlmonks.org?node_id=731150


in reply to Re: Can you do "conjunctive" (overlapping) conditions in a single regexp?
in thread Can you do "conjunctive" (overlapping) conditions in a single regexp?

Thanks & very clever (probably too clever for my little brain ;)- I'm trying though to see whether I can use case #1, rather than your much hairier second example.

I actually want to preserve the field and keep it with the split, so prior to adding the length limitation, I was using:

split /(?=$regex)/, $string
And I want to get only the greediest match (that satisfies the length condition). So, does that mean I can't use first alternative then?

Replies are listed 'Best First'.
Re^3: Can you do "conjunctive" (overlapping) conditions in a single regexp?
by tilly (Archbishop) on Dec 18, 2008 at 04:55 UTC
    You can't use the first version.

    You can use the second version like you did before. Just put the (?=) around the whole thing and insert whatever you want for the pattern in the middle.

    It is ugly but conceptually is not that bad. The first code pattern stores the position of the start of the match in $^R. The second one looks at the current position and the start (which is in $^R) and decides whether or not to make the match fail by interpolating in something that can't match. There are some complication around the logic, but that doesn't need to change.

      Thanks so much for the help & explanation!!!