http://qs321.pair.com?node_id=313376


in reply to Regular Expression Question

/^(?:(?:\d+|\d+-\d+|a)(,\s*|$))+$/

Replies are listed 'Best First'.
Re: Re: Regular Expression Question
by SquireJames (Monk) on Dec 09, 2003 at 07:16 UTC
    That's excellent, thanks muchly.

    Now all I have to do is work out what it's doing....
      use YAPE::Regex::Explain; print YAPE::Regex::Explain->new(qr/^(?:(?:\d+|\d+-\d+|a)(,\s*|$))+$/)- +>explain;
      outputs:
      The regular expression: (?-imsx:^(?:(?:\d+|\d+-\d+|a)(,\s*|$))+$) 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): ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- (?: group, but do not capture (1 or more times (matching the most amount possible)): ---------------------------------------------------------------------- (?: group, but do not capture: ---------------------------------------------------------------------- \d+ digits (0-9) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- \d+ digits (0-9) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- - '-' ---------------------------------------------------------------------- \d+ digits (0-9) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- a 'a' ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- , ',' ---------------------------------------------------------------------- \s* whitespace (\n, \r, \t, \f, and " ") (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- )+ end of grouping ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

      --

      flounder