Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to RegEx

Status
Not open for further replies.

inspleak

Technical User
Mar 10, 2004
14
US
Hey guys. I've got a couple of questions,

I found this someplace while looking for ways to find email addresses in a file:
/(\S+\@\S+\.\S+)/

If I understand this correctly it finds any non-whitespace word (\S) then expects an "@" then matches any non-whitespace word, then a "." then any non-whitespace word.
so it would match me@place.com correct?
But not first.last@my.place.net,

so would this match the second one?
/(\S+\@\S+)/

now I know that it will match non-valid email addresses, however I will deal with that later..

The only other problem would be that it would match
[me@place.com] or <me@place.com>
so I would like to strip off certain characters.

should I use:
@myName = split([|]|<|>);
print "$myName[1]\n";

and have that print the email address between the characters?

Thanks so much for your help! I really Appreciate it!

-jake
 
To search a document for an email use something like this:
first check only for the @ in the line
if(/@/){
#then go deeper
if(/[-._%!*\/+0-9A-Za-z]+@[-0-9A-Za-z.]+\.[A-Za-z]+/){
#valid email
}
}
Here is a sub routine that I borrowed from someone else to verify format of emails. So far it seems to do the trick.

sub checkemail{
my($email) = @_;
if ((!defined$email) || $id !~ /^[-._%!*\/+0-9A-Za-z]+@[-0-9A-Za-z.]+\.[A-Za-z][A-Za-z]+$/){
$email = '';
}
return $email;
}

Hope it works. I haven't tested it.

Thanks
Pat
ideas@microwebber.com
 
inspleak,

Maybe this will give you an idea also,

$str = 'This is an email address first.last@my.place.net and how.';
if($str =~ /([^\s]+)(\@)([^\s]+)/){
$strb = "$1$2$3"; }

HTH
 
You could try something like HTML::FromText, which is designed to (as the name suggests) wrap plain text in html.

May I ask what the purpose is? It sounds like an email harvesting program, which is, at least to me, a very evil thing. Don't send people things they don't ask for.

________________________________________
Andrew - Perl Monkey
 
Thanks for the advise guys I got it working! :)

icrf - actually its for the exact opposite. It is running through the rejected email que to put those email addresses into the "Do not send" list. Worry, not I will save my evil tokens for another day :)

Thanks again!
 
Well at least he says he's not working for the dark side ... so that's ok, isn't it ... isn't it???

Just kidding
--Paul
 
Of course. Evil tokens are far better spent on grander things. :)

________________________________________
Andrew - Perl Monkey
 
yes... like trying to take over the world!
(*que theme song* pinky and the brain, brain, brain, brain, brain....)

Thanks again everyone..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top