Thanks for showing me where that is. I think the regex may be a bit off. I'm not a regex guru and am certainly unfamiliar with positive lookaheads but let me see if I can interpret it, understand why it is not matching, and propose an alternate. I'm testing with a handy regex evaluator at
RegEx: online regular expression testing
(\s|\t|^)\+?(\s?((\(\d{1,4}\))|(\d{1,4}))){6,10}(= ?((\.|\,)?(\n|\r\n|\s|\t|$)))
I think this is saying, start with white space or a tab. Isn't \t included in \s?
We then have an optional single "+" for the country code. At this point, it gets a little fuzzy. I think ((\(\d{1,4}\))|(\d{1,4})) is a statement to mean match one to four digits either within or without parenthesis. Since we are not using backreferences, I would think this would be more efficient as (?:(\(\d{1,4}\))|(\d{1,4})).
We then enclose this statement in parenthesis with optional white space:
(\s?((\(\d{1,4}\))|(\d{1,4}))). Again, I think this would be more efficient as:
(?:\s?(?:(\(\d{1,4}\))|(\d{1,4}))). Please correct me if I am wrong.
This is where I think it breaks. We then take that whole expression and add {6,10}. Doesn't than mean I match a minimum of 6 and maximum of 10 of the previous units? In other words between 6 and 10 groups of 1-4 digits with or without parenthesis?
I'm then really confused by the positive lookahead. I think it is saying that these groups of 6 to 10 groups of digits MUST OPTIONALLY (hence is this really useful) be followed by a "." or "," and some kind of white space (which I would think are all subsumed in \s.
Thus, I think the match makes no provision for "-" and may require far too many digits before it ever allows a "." or ",".
I would propose this:
(?:\s|^)(?:\+\d{1,3})?\s?(?:\(\d{1,4}\))?\s?\d{1,1 1}(?:(?:\-|\.|\,)\d{1,10}){0,3}\s?$
To break it down:
(?:\s|^) nothing or a space at the beginning
(?:\+\d{1,3})? a one to three digit country code - are any longer than three digits?
\s? an optional space
(?:\(\d{1,4}\))? an optional parenthetic code, e.g., area code in the US or (0) in the UK
\s? optional space
\d{1,11} match 1 to 11 digits - who know where the delimiter will be - are any phone numbers longer than 11 digits?
(?:(?:\-|\.|\,\s)\d{1,10}){0,3} optionally have up to three additional clusters of numbers separated by dash, dot, comma, or space (I use \s instead of " " to account for typos, e.g., double space)
\s?$ an optional space at the end
The matching is intentionally loose in that I figured we are better off giving the user the option to dismiss a false match rather than not be able to dial a valid number we did not anticipate.
Would anyone mind testing this against different country phone number formats? So far, it works for any I imagined. Again, I tested using
RegEx: online regular expression testing - no affiliation - just very grateful to have found it. Hope this helps - John