Regular expressions using character classes
Function call Result
preg_match("/[Ff]oo/", "Foo") True
preg_match("/[^Ff]oo/", "Foo") False;
preg_match("/[A-Z][0-9]/", "K9") True
preg_match("/[A-S]esting/", "Testing") False;
preg_match("/[A-T]esting/", "Testing") True;
preg_match("/[a-z]esting[0-9][0-9]/", "TestingAA") False
preg_match("/[a-z]esting[0-9][0-9]/", "testing99") True
preg_match("/[a-z]esting[0-9][0-9]/", "Testing99") False; case sensitivity!
preg_match("/[a-z]esting[0-9][0-9]/i", "Testing99") True; case problems fixed with /i
preg_match("/[^a-z]esting/", "Testing") True;
preg_match("/[^a-z]esting/i", "Testing") False;
Related examples in the same category