This is a discussion on matching everything but a word using ^ and preg_replace within the PHP Language forums, part of the PHP Programming Forums category; I can't fing a way, to match any characters except the phrase 'foo'. Using [^abc]+ matches any character except ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I can't fing a way, to match any characters except the phrase 'foo'.
Using [^abc]+ matches any character except a, b or c, but I need to not match 'foo', because f is ok, o is ok, but foo - 3 letters at once not Any clue? Thanks -- Daniel Kończyk http://konczyk.net |
|
|||
|
In article <slrnbm6lr2.b6.drmartens@gnu.univ.gda.pl>,
Daniel Koczyk <drmartens@voruta.eu.0rg> wrote: > I can't fing a way, to match any characters except the phrase 'foo'. > Using [^abc]+ matches any character except a, b or c, but I need to not > match 'foo', because f is ok, o is ok, but foo - 3 letters at once not > > Any clue? If you just want to match "some pattern when not followed by 'foo'" or "some pattern when not preceded by 'foo'", then you're looking for lookahead or lookbehind syntax. See the section on "Assertions" in <http://us4.php.net/manual/en/pcre.pattern.syntax.php>. For instance, here's two of their examples: *foo(?!bar) *****matches*any*occurrence*of*"foo"**that**is**no t**followed**by *****"bar" *(?<!foo)bar *****does*find*an*occurrence*of*"bar"*that**is**no t**preceded**by *****"foo" -- CC |