in reply to friday morning regex

Hints , or possibly elbow in ribs needed on parsing a Subject: header + to grab the complete string Three (I hope) Subject variations : "foo.com, bar.net, blah.org, trivial.com"; "foo.com, bar.net, blah.org & trivial.com"; "foo.com, bar.net, blah.org and trivial.com"; <SNIP CODE> prints only the first domain, much to my annoyance.
Well $1 obviously only matches foo.com. what you want is to print $_ if you have all 4. Alternatively if you actually want the three separate (and know that there are only three) then you can with do
my ($first, $second, $third, $fourth) = (/^([\w.-]+((,\s?)|(\s&\s)|(\s +and\s)|$))+/)
Probably better to use split and get a list as in
my @topics = split(/(?:,|\s*&|\s*and)\s*/)
Update: fix typos and s/3/4/; I need my coffee too!

Dingus


Enter any 47-digit prime number to continue.

Edit by tye to change PRE to CODE around wide lines

Replies are listed 'Best First'.
Re: Re: friday morning regex
by Anonymous Monk on Nov 08, 2002 at 11:42 UTC
    Split was my fallback plan, but your

    /^(([\w.-]+((,\s?)|(\s&\s)|(\s+and\s)|$))+)/

    ..hasn't failed here yet.
    Where there's a will, there's a wa.. regexp :)

    Cheers dingus

    Simon, UK