Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to get a guid from a email reply

Tags:

regex

guid

Trying to figure out the Regex pattern to match if an email contains a Guid, e.g.

[email protected]

The Guid could potentially be anywhere before the @, e.g.

[email protected]

like image 848
mickyjtwin Avatar asked May 13 '09 06:05

mickyjtwin


2 Answers

I use this to find Guids

Regex isGuid = new Regex(@"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$", RegexOptions.Compiled);
like image 97
WOPR Avatar answered Nov 16 '22 01:11

WOPR


A lazy variant would be

([0-9a-f-]{36}).*?@

It is easy to read and I bet it matches 99,99% of all cases ;) But then in 0,00001% of all cases sombody could have an email address that fits in a GUID scheme.

like image 31
Norbert Hartl Avatar answered Nov 16 '22 02:11

Norbert Hartl