So basically I need to check if a string has 3 or more groups of separated digits, example:
words1 words2 111 222 333 //> YES, it has 3 groups of digits (separated by space)
words 1 2 //> NO
words 2011 words2 2012 2013 //> YES
I was thinking something like
preg_match('/(\b\d+\b){3,}/',$string)
But it’s not working at all (always return false)
Thansk to @Basti i am using this regex now:
'/(\D*\d+\D*){3,}/'
Your regular expression is saying “Find one or more digits at least three times”. What you actually want is: “Find two or more digits surrounded by something I don’t care about at least three times.”:
The problem with your expression is that you are not allowing anything other than digits and word bounds.
Test:
var_dump(preg_match('/(\D*\d{2,}\D*){3,}/',$string, $match), $match);on your three strings.yes123 note:
I am using this function I wrote, it can check for any numbers of groups: