I have this preg_match_all("#findCriteria\((.*) , nkView\.MATCH_THIS#Usi",$string,$matches); Code (markup): The code above doesnt work as expected. I think the problem is somewhere with the spaces before and after the comma. If i replace those spaces with (?:\s) too many unwanted results would be returned. So what to do with those spaces?
i have for example the string 'findCriteria("something", "something_else" , nkView.MATCH_THIS)' . i need to take out '"something", "something_else"' . I don't know how to represend those two spaces in regexp.
It doesnt work for $str='criteria.push(new findCriteria(\'[something]\', 9.046619415283203, \'90,500\', \'90,500\', 90500, 90500, 1.0 , \'$1.14\', 1140330, \'1 - 3\', 2 , 0 , 0 , varyMon, 9 , \'\' , nkView.MATCH_THIS ));'; Code (markup):
Ok, thanks to all for helping me. Now i have another question. How do i match everything until a word nkView ? I tried ((^[nkView])*) . Is it correct?
A common misconception about the character class ( [...] or [^...] ) is that the characters within it are in sequence. This is wrong, an easy way to remember it is that a character class is a big list of characters with | (or) flags between them. The following two patterns are effectively the same. [aceg] Code (markup): a|c|e|g Code (markup): Check out the posts about Lookahead Assertions in this recent thread. http://forums.digitalpoint.com/showthread.php?t=1079610 In your case the pattern might look like this. #findcriteria(.+(?!kview))nkview#i Code (markup): That translates to "match findcriteria, followed by anything one or more times as long as the anything is not followed by kview, followed by nkview".
Thanks for pointing to that resource. It really helped me. A little improvement to suit my needs was to modify your regex like this: #findcriteria(.(?!kview))*?nkview#si Code (markup):