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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl regular expressions

Status
Not open for further replies.

cnw40007

Technical User
Mar 4, 2003
35
IE
Hi
Im reletively new to perl and the use of regexp. I have an email address e.g To:cnw40007@somewhere.com. I want to be able to parse the cnw40007 part using regular expressions and print it out. At the moment i have

open(FILE,'/cnw40007/mbox');

while (<FILE>) {
if (/To:/(\w+)(\d){8}) {
print
}
}
close FILE;

When i try to run it i keep getting errors.Does anybody know what i am doing wrong?
 
In perlre, a delimiter, // by default, has to surround a pattern. In your case, I think you can just move the second / to the end.[tt]
if (/To:[red]/[/red](\w+)(\d){8}) {
[/tt]becomes[tt]
if (/To:(\w+)(\d){8}[red]/[/red]) {
[/tt]But if you want to be more general, you could just cut off the search at the @ symbol, assuming you have fully qualified E-mail addresses. This will match To: followed by one or more characters that is not an @ symbol, and that part is saved in the variable $1 that you can use after a successful match.[tt]
if (/To:([^\@]+)/) {
[/tt]Someone else here probably has something more complete that they've been using and can share. ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Ok the second regexp works, do you have any idea on how i can then compare these addresses of a mysql db.I have set up a db with various different email add's, I can connect to the database but thats as far as it goes im new to perl myself.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top