Solved Regex Help

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

angelr82

Angel
Thread Starter
Joined
Jun 15, 2010
Messages
88
Hello,

So I have a tool that uses Regex to search text. I am trying to extract certain data from the text; in this example I want to find the "TO" data in the email text. Since this data came from Lotus Notes it's formatted slightly different where it doesn't put the : after the To:

Here is what I am using now, it works but pulls too many false positives.
Code:
(?i)(?<=\b(^to |^to:|^to;):?)[^:].+?$
If I remove "^to " then I get no data returned, if I leave it in then I pull a lot of false positives.

How do I match against To and the @ sign for a valid hit?

Example:
******************************************************
From [email protected]
To [email protected]
Subject about regex

To who ever reads this, I am stuck; please help me :)
******************************************************

Anyone have suggestions on how I can use the @ to validate the email address, if no @ then no match?
 

angelr82

Angel
Thread Starter
Joined
Jun 15, 2010
Messages
88
^[To ]+ (\[email protected][a-zA-Z_]+?\.[a-zA-Z]{2,3})$

Try this one
This is going in the right direction but sometimes there will be a name in front of the address. how do i get it to capture everything after the To on that line? or perhaps allow for white spaces before the @ sign?
 
Joined
Jun 8, 2001
Messages
2,583
My Regex is a little rusty, hard to get my mind back in that gear. I would probably do multiple regex just to keep from being confused. If I know how..find the @ then search backward for the to. I'll take another look tomorrow.
 

angelr82

Angel
Thread Starter
Joined
Jun 15, 2010
Messages
88
getting closer; I have this which matches email lines in text with or without domain against To
\b[^to ]+[-\w]{2,40}(\.[-\w]{1,40}){0,5}@[-\w]{2,40}(\.[-0-9a-zA-Z]{2,20})*\b
Only issue is trying to figure out how to capture one more word before white space and the @ email address
 

angelr82

Angel
Thread Starter
Joined
Jun 15, 2010
Messages
88
Ok so I think I have it, posting here for anyone future searching.
Code:
((?i)(?<=\b(^to |^to:|^to;):?)[^:].+?$)+(\b[-\w]{2,40}(\.[-\w]{1,40}){0,5}@[-\w]{2,40}(\.[-0-9a-zA-Z]{2,20}))*\b
This seems to be working; it searches for lines in text that begin with "to" in a few different variations which are easy to customize; it also matches the following formats if lines start with to: ** [email protected] | [email protected] | first last, [email protected] | first last, [email protected] | first last | last, first | first last/name/weird/[email protected] **
I've test a bit but not extensively.
Thank you @draceplace for your help.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top