php - Regular expression doesn't match if text contains certain characters -
i'm trying match string containing characters, not containing others. problem if string contains allowed character, expression finds match, though contains invalid ones (nothing unusual, not want).
expression i'm using looks ([^abc][def])+
.
question is: can define group of characters, if contained within string, stop expression matching string?
you have anchor expression, make sure no other characters in string. example:
^[chars]+\z
or can invert character class , match if invalid character present:
[^chars]
if want combine such checks other expressions in same regex use lookahead:
^(?=[chars]+\z)expression
Comments
Post a Comment