Inigo Posted March 20, 2011 Share Posted March 20, 2011 Hi Guys. This should- hopefully- be a pretty simple question for someone with regex experience to answer. I've been reading all the regex guides and tried various things but none have worked and I'm starting to get a headache. I've decided to just pitch the question here. How do I test if a string contains ONLY a certain character- but could be one or more instances of that character. In this case it's a comma. So: ',' -> Would return TRUE ',,,' -> Would return TRUE ',,,,,,,' -> Would return TRUE ',,,hello,' -> Would return FALSE 'hi,,,' -> Would return FALSE Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/231185-fairly-simple-regex-question/ Share on other sites More sharing options...
sasa Posted March 20, 2011 Share Posted March 20, 2011 if(!preg_match('/[^,]/', $string)) echo 'TRUE'; else echo 'FALSE'; Link to comment https://forums.phpfreaks.com/topic/231185-fairly-simple-regex-question/#findComment-1189969 Share on other sites More sharing options...
Inigo Posted March 20, 2011 Author Share Posted March 20, 2011 NICE. Thanks mate. Link to comment https://forums.phpfreaks.com/topic/231185-fairly-simple-regex-question/#findComment-1189982 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.