
g00dlife
New User
Mar 11, 2003, 6:32 PM
Post #1 of 4
(1362 views)
|
|
smallest match in regexp
|
Can't Post
|
|
I need some help on simple regexp. Just say I have a string for example: $str = "start start start match1 finish finish finish"; I would like to extract the smallest string that is bounded by "start" and "finish"... ie. in this case I would like to extract the string "match1". My first guess was to use: $pat = "start (.*?) finish"; however this matches the string "start start match1". I know I can use the pattern: $pat = ".*start (.*?) finish"; and get what I want, however there's a performance issue by using the greedy matcher .* at the start of the pattern. (This is not important but i'm actually tackling a problem cause by the java package Jakarta ORO... big performace issues by using combinations of greedy and non-greedy matches on large strings.) Is there another single regular expression that will extract "match1" from the above $str when you only know it's bounded by "start" and "finish". Any help would be greatly appreciated.
|