The only thing that overrides a regexes natural greediness is it's desire to achieve a match.Normal regexes are greedy, but not selfish; they are willing to give characters back if it's for the greater good.
But you can use the (?>pattern) construct to create "selfish" regexes: they only try to match once at every position. If the pattern inside is greedy, it will never give up chars to make the entire regex match; if the pattern is lazy, it will never match more than the absolute minimum of chars at that position.
So "1/2 MILE" =~ m[1/2(?>\s*)(?!MILE)] should work.
In reply to Re: Re: regex negative lookahead behaviour
by pijll
in thread regex negative lookahead behaviour
by shemp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |