Reputation: 95
Hi Have the Following Regex written.
(?<!x)(\d{9}|\d{3}-\d{6}|\d{3}-\d{3}-\d{3})
I want to modify the existing Regex so that the below use cases can get a match, right now only few are matching.
Note:
Use cases:
This is a list of Use cases that needs to be Matched
https://regex101.com/r/iFiwx5/1
Example: These are the use cases that needs to be matched with the regex.
Any help on this would be really good.
Upvotes: 2
Views: 52
Reputation: 785058
If I understand problem correct, you may use this regex:
(?<!x)(?=(?:[._ –-]*\d){9})\d{2,}[._ –-]*\d{2,}[._ –-]*\d{2,}
Explanation:
(?<!x)
Make sure digits are not preceded with letter x
(?=(?:[._ –-]*\d){9})
ensures presence of at least 9 digits separated with 0 or more allowed delimiters[._ –-]*
: allows for presence of 0 or more of these delimiters every 2 or more digitsUpvotes: 3