I have an email field that may be formatted in a few different ways.
-
hello@world.com -
"hello world" <hello@world.com> -
hello world <hello@world.com>
I would like to capture both the hello world string (if it’s there) and the email address (if it’s there). I have a regular expression that almost works, but it doesn’t quite.
sed -r 's/"?([^"]+)*"?\s<?([^>]+@[^>]+)>?/["\1","\2"]/' <<< 'Hello World <helloworld@gmail.com>'
Please help?
Update:
This should do what you want:
This will store the first part, if there is one, into the first capturing group and the email address int o the second group.