Reputation: 63
I need to match phone numbers with this format
(555) 555-5555
I have found around this
\(?\b[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}\b
I know that is the correct way but in the platform that I am using there is a bug that removes the {} brackets out of the regex code. I have already reported the bug but it might take a while for them to fix it and release the update so I am wondering if there is another way to accomplish the same with out using brackets.
Upvotes: 0
Views: 1815
Reputation: 2459
Simply replace the brackets with the given number of iterations of the sequence before the bracket.
\(?\b[0-9][0-9][0-9]\)?[-. ]?[0-9][0-9][0-9][-. ]?[0-9][0-9][0-9][0-9]\b
Upvotes: 0
Reputation: 30947
Well, sure. Instead of saying "apply pattern {n} times", write "patternpatternpattern..." n times:
\(?\b[0-9][0-9]0-9]\)?[-. ]?[0-9][0-9][0-9][-. ]?[0-9][0-9][0-9][0-9]\b
Upvotes: 0
Reputation: 207511
just use \d
for each characcter you need to match
[0-9]{3}
is \d\d\d
[0-9]{4}
is \d\d\d\d
Upvotes: 0
Reputation: 19076
[0-9]{3}
is the same thing as [0-9][0-9][0-9]
or \d\d\d
In full that would look like this:
\(?\b[0-9][0-9][0-9]\)?[-. ]?[0-9][0-9][0-9][-. ]?[0-9][0-9][0-9][0-9]\b
or
\(?\b\d\d\d\)?[-. ]?\d\d\d[-. ]?\d\d\d\d\b
Upvotes: 5