RegEx - search for emails inside a log file

I'm looking for a regex that will check for matches against a string, for example:

mxtreme1.log: May 12 07:00:00 10.1.1.175 postfix / cleanup [48145]: C2C9FFA730: filename =, sender=LOGINNAME@company.com , from = LOGINNAME @company. com, recip=LOGINNAME@company.com , before =, as_score = 0, as_strategy = M, code = W, actions = FFFFFFFFFFFTFFFFFFFFFF, parsing = F000FFF000TTT000F000TFT000000TTSS3000059900033-F1F-FF00000000F000FFF000000000000F1F-FF00000000F000FFF000000000000

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

Any help would be greatly appreciated, Thanks,

+1


a source to share


5 answers


It will be something like:

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


(You have explicitly indicated that only the LOGINNAME part will be variable.)

+2


a source


To test all of the above solutions, I personally love using "The Regex Coach"

Just google for this line and its free software that serves me well.



PS: I do not own and have no interest in the product or the team that built it.

+2


a source


I'm pretty sure the comma is not valid inside the email address, so if it always has a comma after that, you can get it with:

/(sender=[^,]+?),/

      

+1


a source


Here's the regex for RFC2822 email addresses .

Surprisingly long, email addresses can be more complex than you might expect.

Just attach it to /sender\s*=\s*/

to receive the sender's email messages.

0


a source


You can try this:

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

      

But check out this post to find out why RegEx and email are problematic.

Also this to add SENDER =:

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

      

0


a source







All Articles