Forum Moderators: coopster
One I would like clarification on is the "(?!"
I used it as follows: /^(?!car¦truck)/i
is this right or should it be /^(?!car¦!truck)/i
My gut tells me the former is correct because I can't find any mention of '!' anywhere in the PCRE PHP pages except after '(?' but when I read the pattern I find I can read it as such.. which is corrrect?
-------------------------
/^(?!car¦truck)/i
-------------------------
start of line does not match car or truck
or
start of line does not match car or matches truck
would be a zero-width negative lookahead for "car" (so a match would occur if the next three characters were something other than "car" and it would not advance the cursor in event of a match).
Without testing, I believe that
(?!(car¦truck))
should give you your "line does not start with car or truck" match.
although I have tried both ways and so far they do the exact same thing, that is they do what I expect it to, although my data I'm looping through so far has only had either of the two pattern matches.
I need to wrap my head around the "lookarounds" and zerowidth stuff more thoroughly.
I like your code better though.. it makes sense so I'll just use that :P
Thanks