Why is my regex is not matching a phone number that I require?

Viewed 177

My book "Automate the boring stuff with Python" has this complex regex which tries to get the phone number in a given string:

((\d{3}|\(\d{3}\))?(\s|-|\.)?\d{3}(\s|-|\.)\d{4}(\s(ext|x|ext.)\s*\d{2,5})?)

222-666-7777 ext 322 is the phone number that I think should match with the regex but it doesn't. I was using regex101 and here is the link to my regex : https://regex101.com/r/OIMqNB/1. Could someone please tell me where am I going wrong?

2 Answers
Related