in reply to Building an SQL query

Geez, I can't seem to match this pattern correctly:
$somename <$someaddress>

Replies are listed 'Best First'.
RE: Re: Building an SQL query
by Fastolfe (Vicar) on Oct 20, 2000 at 00:17 UTC
    What "pattern" is that? Are you trying to build a regular expression to match each component there, so that you can pull out full names and e-mail addresses from text? Or are you trying to build a pattern out of $somename and $someaddress and match that against some known text to see if that combination exists? You'll need to be more descriptive with what you're trying to do.

    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:

    $somename = qr/[\w\.\s]+/; $someaddress = qr/[\w\.+]+@[\w\.]+/; if (/($somename) <($someaddress)>/) { print "Got a name of '$somename'\n"; print "Got address of '$someaddress'\n"; }
    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).

    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:

    $somename = 'David Nesting'; $someaddress = 'david@example.com'; $_ = 'David Nesting <david@example.com>'; if (/^$somename <$someaddress>$/) { print "Yep, this one is $somename!\n"; }
    I hope this helps. Otherwise, please provide more information.
RE: Re: Building an SQL query
by swiftone (Curate) on Oct 20, 2000 at 01:10 UTC
    The code I posted above split on a look-ahead for the first < (Which means it assumes your "name" fields don't have that. Note everything that Fastolfe said about Email addresses is true, they're quite difficult to validate/match for all possible cases.