[PHP] (Perl) Regular Expressions - oposite match or get the non-matches of a substring
Hi all, I consider myself quite good with Regular Expression, but i could never find out how to match something like: "match this but not this and that" so i would like to match the first "match this" (or "another this") but not "not this". Seems pretty straight forward but i haven't found a (good) solution yet. Please no solutions with extra code, i know how to do that. I need a regular expression that can do it, preferably Perl compatible. Surprisingly i couldn't figure out how to say '/!(not) this/'. Seems like there must be a simple way, but i can't seem to figure it out. Tried things like: '/[^n][^o][^t] this/', '/[^not]{3} this/' etc but all of those don't work. Looked in various books and websites but didn't find what i was looking for... Please enlighten me if you can. Regards, Tim Tim-Hinnerk Heuer http://www.ihostnz.com Bob Hope - "I have a wonderful make-up crew. They're the same people restoring the Statue of Liberty."
Re: [PHP] (Perl) Regular Expressions - oposite match or get the non-matches of a substring
German Geek wrote: > I consider myself quite good with Regular Expression, but i could > never find out how to match something like: > > "match this but not this and that" > > so i would like to match the first "match this" (or "another this") > but not "not this". > > Seems pretty straight forward but i haven't found a (good) solution > yet. Check out "look-around" (-behind, -ahead), here for instance: http://www.regular-expressions.info/refadv.html > Surprisingly i couldn't figure out how to say '/!(not) this/'. Seems !/this/ /Per -- Per Jessen, Zürich (0.4°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] (Perl) Regular Expressions - oposite match or get the non-matches of a substring
> Hi all, > > I consider myself quite good with Regular Expression, but i could never find > out how to match something like: > > "match this but not this and that" > > so i would like to match the first "match this" (or "another this") but not > "not this". > > Seems pretty straight forward but i haven't found a (good) solution yet. > Please no solutions with extra code, i know how to do that. I need a regular > expression that can do it, preferably Perl compatible. Surprisingly i > couldn't figure out how to say '/!(not) this/'. Seems like there must be a > simple way, but i can't seem to figure it out. > > Tried things like: '/[^n][^o][^t] this/', '/[^not]{3} this/' etc but all of > those don't work. Looked in various books and websites but didn't find what > i was looking for... > try this /match this but (?!not this and that)/ goodluck! Virgil http://www.jampmark.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php