in reply to Re: split on commas
in thread split on commas

Yes, this is what I need. Perhaps you can explain your split line?

Thanks!

Replies are listed 'Best First'.
Re^3: split on commas
by toolic (Bishop) on Jun 05, 2009 at 18:39 UTC
    Using YAPE::Regex::Explain:
    #!/usr/bin/env perl use strict; use warnings; use YAPE::Regex::Explain; print YAPE::Regex::Explain->new(',(?![\w,]+[>)])')->explain(); __END__ The regular expression: (?-imsx:,(?![\w,]+[>)])) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- , ',' ---------------------------------------------------------------------- (?! look ahead to see if there is not: ---------------------------------------------------------------------- [\w,]+ any character of: word characters (a-z, A-Z, 0-9, _), ',' (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- [>)] any character of: '>', ')' ---------------------------------------------------------------------- ) end of look-ahead ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
      Cool, I wasn't aware of this module. Thanks!
Re^3: split on commas
by Anonymous Monk on Jun 05, 2009 at 18:37 UTC
    With comments:
    $_ = "<*2>FOO<2,1>,<*3>(SigB<8:0:2>,BAR),<*2>Siga<2:0>,Sigb<8,7,6,5,0> +"; @line = split(/ , # comma... (?! # not followed by [\w,]+ # "word" characters or commas and [>)] # a close-bracket or close-paren ) /x, $_); print join($/, @line), $/;
      Thanks!
        the problem with this approach is that it erroneously accepts input such as
        $_ = "<*2)FOO<2,1>,<*3>(SigB<8:0:2>,BAR),<*2>Siga<2:0>,Sigb<8,7,6,5,0> +";
        (where the first < matches a )

        you really need a parser to do this kind of thing "right".