X
Xavier Noria
I was playing with variable-width negative look-behind emulation and
worked out this regexp that supports assertions about substrings of
the pre-match:
/^.*(??{ index($&,"foo") == -1 ? "" : "(?!)" })bar/
That matches "bar" if it is not preceded at any point by "foo". I know
that can be achieved by reverse + negative look-ahead but this has to
be considered an exercise (that comes from a question in freenode#perl
that required a single regexp to solve the problem).
I tried a few tricks to extend that to patterns as
/^.*(??{ $& =~ m,fo+, ? "(?!)" : "" })bar/
or
/^.*(?{ local $m = $& })(??{ $m =~ m,fo+, ? "(?!)" : "" })bar/
and the like, but I got segmentation faults (maybe that hits some
corner of the documented experimentalness of that stuff). Looks like
the problem comes from nesting m//, but that's a guess.
Any comments?
-- fxn
worked out this regexp that supports assertions about substrings of
the pre-match:
/^.*(??{ index($&,"foo") == -1 ? "" : "(?!)" })bar/
That matches "bar" if it is not preceded at any point by "foo". I know
that can be achieved by reverse + negative look-ahead but this has to
be considered an exercise (that comes from a question in freenode#perl
that required a single regexp to solve the problem).
I tried a few tricks to extend that to patterns as
/^.*(??{ $& =~ m,fo+, ? "(?!)" : "" })bar/
or
/^.*(?{ local $m = $& })(??{ $m =~ m,fo+, ? "(?!)" : "" })bar/
and the like, but I got segmentation faults (maybe that hits some
corner of the documented experimentalness of that stuff). Looks like
the problem comes from nesting m//, but that's a guess.
Any comments?
-- fxn