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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -