in reply to Tell regex to stop at "phrase", instead of char - how?
Maybe I'm missing something subtle here, but the answers so far seem too complicated.
If you want to stop at the phrase 'stop', just embed that at the appropriate point in the regex and use an non-greedy 'anything' match:
$s = "this is a load of junk to be consumed until we get to the word s +top. After that nothing should stop it until another stop";; print $1 while $s =~ m[(.+?)stop]g;; this is a load of junk to be consumed until we get to the word . After that nothing should it until another
And if you want the stop phrase to be a part of (say) the next capture, only then do you need to wrap it in a ZLA:
print $1 while $s =~ m[(.+?)(?=stop)]g;; this is a load of junk to be consumed until we get to the word stop. After that nothing should stop it until another
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Tell regex to stop at "phrase", instead of char - how? (greed)
by tye (Sage) on Aug 02, 2007 at 21:45 UTC |