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? Quote Link to comment https://forums.phpfreaks.com/topic/293693-noobie-preg_match-question/ Share on other sites More sharing options...
Solution CroNiX Posted January 5, 2015 Solution Share Posted January 5, 2015 (edited) You aren't putting delimiters around your regex expression. Try if (preg_match("/[0-9]/", "2")) { Edited January 5, 2015 by CroNiX Quote 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) 2 Quote 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/293693-noobie-preg_match-question/#findComment-1501866 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.