Jump to content
Sign in to follow this  
LurchMan

StringRegExp Question

Recommended Posts

LurchMan

Hey Everyone -

I'm working on a small script that is going to read emails out of outlook with the subject line "spam". I've already figured out how to do this but the issue I'm having is I can't figure out how to extract email address out of the body of the email. Almost all of the emails have "mailto:something@spam.com" in the body because they are forwarded to me, but some of them don't. I was wondering if there was a way to do this using StringRegExp to get just the email address.

Hope I explained this well enough, let me know if I didn't

Thanks for any help in advance

Lurch


Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites
GEOSoft

$sSre = ".*(\b.+@.+\b).*", "$1"
$sAddress = "mailto:something@spam.com"
$sAddress = StringRegExpReplace($sAddress, $sSre, "$1")
MsgBox(0, "Result 1", $sAddress)

$sAddress = "noreply@spamit.com"
$sAddress = StringRegExpReplace($sAddress, $sSre, "$1")
MsgBox(0, "Result 2", $sAddress)


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
GEOSoft

I should have added that you will need some method to get the message header before you use the code I posted. If you still have trouble then I'll have a look at a standard .eml file and work it out from there. It runs in my mind that the line you are looking for is something like ReplyTo:somename@someaddress.com

It that is correct then $sSre would be

"(?i)(?m:^)ReplyTo.*(\b.+@.+\b).*", "$1"
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
LurchMan

$sSre = ".*(\b.+@.+\b).*", "$1"
$sAddress = "mailto:something@spam.com"
$sAddress = StringRegExpReplace($sAddress, $sSre, "$1")
MsgBox(0, "Result 1", $sAddress)

$sAddress = "noreply@spamit.com"
$sAddress = StringRegExpReplace($sAddress, $sSre, "$1")
MsgBox(0, "Result 2", $sAddress)

Thank you for your quick response.

and maybe my brain just isn't working yet but why would I use StringRegExpReplace rather than StringRegExp?

Edit: I tried using both and i get the result i expected with StringRegExp. Thank you for your help!

Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites
GEOSoft

Thank you for your quick response.

and maybe my brain just isn't working yet but why would I use StringRegExpReplace rather than StringRegExp?

Edit: I tried using both and i get the result i expected with StringRegExp. Thank you for your help!

Either would work. I just used the Replace to strip out everything except the email address. Using the RegEx with the 1 0r 3 flags will return an array of all email addresses found and that could actualy be beneficial in that it would allow you to select the address you wanted. Using it with the 0 flag (same as no flag) will tell you if there is an email address in the message.

Question: Are you using this with standard *.eml files?

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.