I have the current regex pattern:
(.*?)?(?:<)?([\w\.-]+@[\w\.-]+)(?:>)?(.*)?
I have input strings in the form name <email> with the <> included, but sometimes omitted (the reason why I made them a non capturing group). Occasionally I might have text after the email, like name <email> fshasodi for which I've added an extra group to capture it.
Now the problem with my regex is that if there is no email in the string, then it doesn't match the expression. How do I make the email also optional? I understand that it would make all the groups optional, is there a better way I can be doing this in?
^(.*?)(?:<?([\w.-]+@[\w.-]+)>?(.*))?$