Dunestrider Posted January 5, 2015 Share Posted January 5, 2015 Why oh why does this not work? <?php if (preg_match("[0-9]", "2")) { echo("OK!"); } else { echo("NO MATCH"); } ?> I would think "2" is in the range of 0 to 9, but it always outputs "NO MATCH". Any ideas? Link to comment https://forums.phpfreaks.com/topic/293693-noobie-preg_match-question/ Share on other sites More sharing options...
CroNiX Posted January 5, 2015 Share Posted January 5, 2015 You aren't putting delimiters around your regex expression. Try if (preg_match("/[0-9]/", "2")) { Link to comment https://forums.phpfreaks.com/topic/293693-noobie-preg_match-question/#findComment-1501844 Share on other sites More sharing options...
hansford Posted January 5, 2015 Share Posted January 5, 2015 Some people when confronted with a problem think, “I know, I'll use regular expressions.” Now they have two problems. (Jamie Zawinski, Usenet, "alt.religion.emacs", August 12, 1997) Link to comment https://forums.phpfreaks.com/topic/293693-noobie-preg_match-question/#findComment-1501865 Share on other sites More sharing options...
Dunestrider Posted January 5, 2015 Author Share Posted January 5, 2015 You aren't putting delimiters around your regex expression. Try if (preg_match("/[0-9]/", "2")) { Thanks! You are a genius!!! Link to comment https://forums.phpfreaks.com/topic/293693-noobie-preg_match-question/#findComment-1501866 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.