in reply to State this simple regex in English?

Is this any better? Tip #9 from the Basic debugging checklist: YAPE::Regex::Explain

The regular expression: (?-imsx:CAT[2-9]*$) 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): ---------------------------------------------------------------------- CAT 'CAT' ---------------------------------------------------------------------- [2-9]* any character of: '2' to '9' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

Replies are listed 'Best First'.
Re^2: State this simple regex in English?
by misterperl (Friar) on Apr 20, 2016 at 17:22 UTC
    thanks guys,

    STILL seems a bit ambiguous since, afterall, there ARE 0-many 2-9's at the end (there are 0 of them!)... But I suppose it only makes sense to act like this because otherwise it would behave just like /CAT.*/

    YAPE::Regfex::Explain looks cool never tried it or knew about it, thanks for that tip...

      if your regex were "simply" CAT[2-9]* then CAT1 would match, but the $ (which means end of string) in CAT[2-9]*$ prevents a match.
      Would you expect C1AT to match?
      YAPE::Regfex::Explain looks cool ...

      It does, but of course be aware that, per the docs, "There is no support for regular expression syntax added after Perl version 5.6, particularly any constructs added in 5.10."


      Give a man a fish:  <%-{-{-{-<

      You may also be interested in use re 'debug';