tags:

views:

62

answers:

5

Hey everyone,

I am looking for a regular expression that will test for matches against a string such as:

mxtreme1.log:May 12 07:00:00 10.1.1.175 postfix/cleanup[48145]: C2C9FFA730: fullname=, sender=LOGINNAME@company.com, [email protected], [email protected], prior=, as_score=0, as_strategy=M, code=W, actions=FFFFFFFFFFFTFFFFFFFFFF, analysis=F000FFF000TTT000F000TFT000000TTSS3000059900033-F1F-FF00000000F000FFF000000000000F1FFF000F000

where the entire part in bold is a match, but LOGINNAME can be any number of random characters.

Any help would be greatly appreciated, Thank you,

+1  A: 

I'm pretty sure that a comma isn't valid inside of an email address, so as long as it always has the comma afterwards, you should be able to get it with:

/(sender=[^,]+?),/
Chad Birch
+2  A: 

That would be something like:

sender=[^@]+@company\.com

(You were explicitly stating that only the LOGINNAME part would be variable.)

Tomalak
A: 

Here's the regex for email addresses according to RFC2822.

It's surprisingly long, but email addresses can be more complex than you may expect.

Just prefix it with /sender\s*=\s*/ to only get sender emails.

rampion
A: 

You can try this:

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$

But look at this post to get why RegEx and emails address are problematic.

Also this to add the SENDER=:

^[\w]+=[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$
Phill Pafford
+2  A: 

To test all of the above solutions, i personally love using 'The Regex Coach'

Just google for that string and its a freeware that has served me well.

PS: I dont own nor have any sort of vested interest in the product or the team that built it.

thisismydisplayname