I am trying to match some email addresses using regular expressions in bash. Currently received expression
"^[a-zA-Z0-9!#\$%&'\*\+/=?^_\`{|}~-]+(\.[a-zA-Z0-9!#\$%&'\*\+/=?^_\`{|}~-]+)*@([a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?\$"
Which successfully matches all the email addresses I need, but when I try to add the "To:" field, I cannot get any matches, and I'm not sure why. This is my code with the To field.
"^To:\s[a-zA-Z0-9!#\$%&'\*\+/=?^_\`{|}~-]+(\.[a-zA-Z0-9!#\$%&'\*\+/=?^_\`{|}~-]+)*@([a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?\$"
Which AFAIK should go well with "To: bob@bob.co.uk ", but not :( Any tips?
Code example
Reply-To: " service@paypal.com " < service@paypal.com > To: bob@bob.co.uk Date: Mon, 21 Jun 2012 21:34:10 -0300
Code used to find a file and add to an array
regex="^[a-zA-Z0-9!#\$%&'\*\+/=?^_\`{|}~-]+(\.[a-zA-Z0-9!#\$%&'\*\+/=?^_\`{|}~-]+)*@([a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?\$" for i in $(cat mailbox.mbx); do if [[ $i =~ $regex ]]; then echo $i sortarray[$index]=$i index=$(($index+1)) fi done
user1298620
source share