Tech Support Guy banner
Status
Not open for further replies.

Regex Help

Solved 
Tags
regex
1K views 6 replies 2 participants last post by  angelr82 
#1 ·
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 me@me.com
To you@you.com
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?
 
See less See more
#5 ·
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.
 
#7 ·
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: ** name@email.com | no@domain | first last, name@email.com | first last, name@email | first last | last, first | first last/name/weird/lotusnotes@domain **
I've test a bit but not extensively.
Thank you @draceplace for your help.
 
Status
Not open for further replies.
You have insufficient privileges to reply here.
Top