randor1973
asked on
regex question
ok,
i need to pull an email address from a line like so:
$read = 'hello and welcome to my place, my email address is me@myplace.com in case you want to write me';
now the problem is that the text/email will not be the same each time.. so far i got this:
$read =~ m/(\s.*?\@.*\..*\s)/i; but this pulls out everything from the first space to the one right after the email address..
can someone show me where i am going wrong on that??
Thanx
ps: sry for the points, but it seems that my points that i did have have dissapeared??
i need to pull an email address from a line like so:
$read = 'hello and welcome to my place, my email address is me@myplace.com in case you want to write me';
now the problem is that the text/email will not be the same each time.. so far i got this:
$read =~ m/(\s.*?\@.*\..*\s)/i; but this pulls out everything from the first space to the one right after the email address..
can someone show me where i am going wrong on that??
Thanx
ps: sry for the points, but it seems that my points that i did have have dissapeared??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks.
Here is a a better solution that demands at least one dot in the address, and is not fooled by a comma or a period at the start of the address, or a comma at the end of the address.
$read =~ m/([^\s.,]*\@[^\s.,]+\.[^\ s,]+)/i;
It is not perfect because, for example, it is fooled by a period at the end of an address. It is up to you to add as much checking as is justified is your circumstances.
On the command line enter
perldoc -q "How do I check a valid mail address?"
for more info
Here is a a better solution that demands at least one dot in the address, and is not fooled by a comma or a period at the start of the address, or a comma at the end of the address.
$read =~ m/([^\s.,]*\@[^\s.,]+\.[^\
It is not perfect because, for example, it is fooled by a period at the end of an address. It is up to you to add as much checking as is justified is your circumstances.
On the command line enter
perldoc -q "How do I check a valid mail address?"
for more info
ASKER