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

Greeting, I'm still new to adapt Perl's regex feature.

Let say I'm passing statement from one of xml value

{name eq \'Apple, Tomato, Orange\'}

I would like to separate name, eq, and (apple, tomato, orange).

($name, $cond, $array) = s/???????????/

What would be the great way to put this, and could you recommand some of regex practice website?

Replies are listed 'Best First'.
Re: Set condition values with regex.
by Athanasius (Archbishop) on Mar 05, 2013 at 15:20 UTC

    Try this:

    #! perl use strict; use warnings; use Data::Dump; my $s = q[{name eq \'Apple, Tomato, Orange\'}]; if ($s =~ /^\{(\w+)\s+(\w+)\s+\\'(.*)\\'\}$/) { my @array = split /,\s*/, $3; print "name: $1\n"; print "condition: $2\n"; print 'array: '; dd @array; } else { print "No match found\n"; }

    Output:

    1:16 >perl 559_SoPW.pl name: name condition: eq array: ("Apple", "Tomato", "Orange") 1:17 >

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Superb!!!! Thanks!!!
Re: Set condition values with regex.
by Anonymous Monk on Mar 05, 2013 at 15:25 UTC
      Thanks!