in reply to Newbie RegEX question

Assuming your data is as simple as that provided
$_ = '001WhitePottery.jpg'; my($serial, $name, $cat) = m< ^ (\d+) ([A-Z][a-z]+) ([A-Z][a-z]+) >x; print "($serial) Serial\n", "($name) Name of Product\n", "($cat) Category\n"; ___output__ (001) Serial (White) Name of Product (Pottery) Category
See. perlre and perlop for more info.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Newbie RegEX question
by Limbic~Region (Chancellor) on May 13, 2003 at 15:07 UTC
    broquaint,
    I agree - ".. the data is as simple as that provided". I would only say that it might be worthwhile to create a catch bucket for the purpose of refining the RE over time to catch more and more a-typical cases.
    my @bitbucket; $_ = '001WhitePottery.jpg'; if (m< ^ (\d+) ([A-Z][a-z]+) ([A-Z][a-z]+) >x) { my($serial, $name, $cat) = ($1, $2, $3); print "($serial) Serial\n", "($name) Name of Product\n", "($cat) Category\n"; } else { push @bitbucket , $_; } print "The following files didn't match rule - please fix"; print "$_\n" foreach (@bitbucket);

    I only point this out as the OP claimed newbie status.

    Cheers - L~R