danambrose has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

Iam looking to extract the quoted values from this string..

enum('one','two','three','four')

What would be the best regex to do this most effectivly.
Thanks,
Dan

Replies are listed 'Best First'.
Re: Enum Regex
by reneeb (Chaplain) on Nov 05, 2004 at 09:48 UTC
    #! /usr/bin/perl my $string = "enum('one','two','three','four') "; my @values = $string =~ /'([^']+)'/g; print $_,"\n" for(@values);
Re: Enum Regex
by gaal (Parson) on Nov 05, 2004 at 09:48 UTC
    Are the quoted values guaranteed not to have single quotes inside them? If so:

    my @names = /'(.*?)'/g; If you do need to protect against embedded quotes, take a look at Text::Balanced.

    Update: removed silly extraneous .*? at end of regexp.

Re: Enum Regex
by Joost (Canon) on Nov 05, 2004 at 09:44 UTC