it is my first time when I'm asking here for a solution after a long period of searching, and I want to tell you that I'm struggling to find the solution from days now for my particular and specific case, or maybe I missed it, but at least I will provide you with all the info you need. I've found and read many possible ways to solve my python regex, but I only found regexes only for isolated digits, characters or symbols, but not for an entire phone number in a simple specific format.
I will put here the content format of the text from where I'm trying to extract names, their phone numbers and email addresses (I apologize for not formatting but I don't know how to break lines in code area):
A lot of text... First Name1 0723-111-222 email@address1.com ...a lot of text
A lot of text... Second Name2 0723-333-444 ...a lot of text
A lot of text... Third Name3 email@address3.com ...a lot of text
A lot of text... Fourth Name4 0723-777-888 email@address4.com ...a lot of text
A lot of text... Fifth Name5 0723-999-000 email@address5.com ...a lot of text
The sequences of the text I want to extract it looks like this First Name1 0723-111-222 email@address1.com
and so on. Now I have a regex that actually does this successfully, but with one exception. As you can see in the text sample above, also I have one string without email address and other string without phone number. So, the string without the email address is extracted successfully, but the one with the missing phone number is not, and in the script output is not printed.
The regex I'm running is this and I'm very close to get what I want:
'\w+s?\w+s?\w+\s\w+\s(?:\d+\-\d+\-\d+)?\s(?:[A-Za-z0-9\.\-+_*]+@[a-z0-9\.\-+_]+\.[a-z]+)?'
After I'm running the script the output is like:
First Name1 0723-111-222 email@address1.com
Second Name2 0723-333-444
Fourth Name4 0723-777-888 email@address4.com
Fifth Name5 0723-999-000 email@address5.com
So the main problem is with the (?:\d+\-\d+\-\d+)?
sequence of regex that is not printing the Third Name3 email@address3.com
in the output. What I need to add to the regex to be optional where the phone number is missing?
Sorry for the long description, but I wanted to provide enough info for you to understand what is the problem