Regex Explainer, v3.01

They have: 161 posts

Joined: Dec 1999

For those of you suffering from regex-induced headaches, I announce release 3.00 of YAPE::Regex, and release 3.01 of YAPE::Regex::Explain.

Both modules can be found on CPAN, as well as the YAPE web site (http://www.pobox.com/~japhy/YAPE/).

Here's sample output from the 'explain' program; the regex being fed through is from: s!(/?[^/]+/).*(/[^/]+)$!$1...$2!, which can be used to change "/this/that/those/thine.ext" to "/this/.../thine.ext".

(?-imsx:(/?[^/]+/).*(/[^/]+)$)

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):
----------------------------------------------------------------------
  (                        group and capture to \1:
----------------------------------------------------------------------
    /?                       '/' (optional (matching the most amount
                             possible))
----------------------------------------------------------------------
    [^/]+                    any character except: '/' (1 or more
                             times (matching the most amount
                             possible))
----------------------------------------------------------------------
    /                        '/'
----------------------------------------------------------------------
  )                        end of \1
----------------------------------------------------------------------
  .*                       any character except \n (0 or more times
                           (matching the most amount possible))
----------------------------------------------------------------------
  (                        group and capture to \2:
----------------------------------------------------------------------
    /                        '/'
----------------------------------------------------------------------
    [^/]+                    any character except: '/' (1 or more
                             times (matching the most amount
                             possible))
----------------------------------------------------------------------
  )                        end of \2
----------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------
'