|
Reg Expression is Greedy
How can I keep ereg_replace or preg_replace from being greedy?
Want the match to return first occurance of the regex, not the last.
In other words:
$str = "AA TAKE ME AWAY PPP AA XYZ PPP AA XYZ PPP jfkldjflkdjfsa PPP";
$str = ereg_replace ("AA.*PPP", "", $str);
I want to whack out "AA TAKE ME AWAY PPP" - not the whole string. The only alternative I've been able to find is using {min,max} but this is imprecise because I never know how many characters are going to be in the other, unwanted matches.
Basically, I just want the first occurance found, not the greedy, biggest one that regex otherwise mandates.
Also - the above places a blank space in the string - how do I insert NOTHINGNESS?
Thanks in Advance
|