in reply to Re: Building an SQL query
in thread Building an SQL query
If you're trying to see if a string matches your (simple) definitions of a full name and an e-mail address, you're going to have to define (in regex terms) what $somename and $someaddress really are. Perhaps something like this:
Note that this is generally not the best way of looking for e-mail addresses in plain text. The relevant RFC's describe very complex rules for valid SMTP addresses, and it is going to be very difficult for you to build a quality set of regular expressions that will be able to pull these out of text. You may be interested in Email::Find to locate e-mail addresses, and Email::Valid to validate a sample string as an e-mail address (does not search for it, just validates an assumed address).$somename = qr/[\w\.\s]+/; $someaddress = qr/[\w\.+]+@[\w\.]+/; if (/($somename) <($someaddress)>/) { print "Got a name of '$somename'\n"; print "Got address of '$someaddress'\n"; }
On the other hand, if your intent is to build a pattern out of those two variables, to see if a particular line matches someone's name and e-mail address, you could easily do something like this:
I hope this helps. Otherwise, please provide more information.$somename = 'David Nesting'; $someaddress = 'david@example.com'; $_ = 'David Nesting <david@example.com>'; if (/^$somename <$someaddress>$/) { print "Yep, this one is $somename!\n"; }
|
|---|