Reputation: 1481
I'm trying to combine a couple simple email PCRE regex checks for Postfix. I'll be honest, this is not my area of expertise.
Is there a way to combine the 2? or should they be left separate?
I know I need the < > to be optional, but adding ? to them did nothing.
This handles "<[email protected]>, <[email protected]>" format
(?:To|Cc):(?:.+?<.+?[@].+?>){2,}
This handles "[email protected], [email protected]" format
(?:To|Cc):(?:.+?[@].+?),.{2,}
Any help would be greatly appreciated.
Upvotes: 1
Views: 61
Reputation: 785128
You can use this regex with optional <
and >
on either side of email address:
(?:To|Cc):(?:\h*<?\w[^@]*@\S+>?,?){2,}
This will match both of these inputs:
To: <[email protected]>, <[email protected]>
Cc: [email protected], [email protected]
Upvotes: 2