Hello, If I use ([^string]+) in a regex, it will capture everything until it matches any s, t, r, i, n or g, right? how to capture everything until it matches the whole string as a... string ? Logically I would have done this: ([^(?:string)]+) but it doesn't seem to work.. thanks for your help
Lookahead assertions. <? $str1 = 'stay out of the weed'; $str2 = 'stay out of the weeds'; $pattern = '#^(.+(?=weeds?))#si'; $matches = array(); preg_match($pattern, $str1, $matches[0]); preg_match($pattern, $str2, $matches[1]); echo sprintf('<pre>%s</pre>', print_r($matches, true)); ?> Code (markup):
They're kinda confusing at first. One thing that gets me sometimes is remembering to use the occurance specification before the assertion. .+(?=ahead) // instead of .(?=ahead)+ Code (markup): I think the error it gives me is something along the lines of "Nothing to repeat at index X".