<?xml version="1.0" encoding="windows-1252"?>
<node id="548905" title="Re: What this pattern matches" created="2006-05-12 01:09:25" updated="2006-05-11 21:09:25">
<type id="11">
note</type>
<author id="169829">
Enlil</author>
<data>
<field name="doctext">
With a little [cpan://YAPE::Regex::Explain] magic:
&lt;code&gt;
$ perl -MYAPE::Regex::Explain -e 'print YAPE::Regex::Explain-&gt;new(qr/^(.+)_[^_]+$/)-&gt;explain' 

The regular expression:

(?-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):
----------------------------------------------------------------------
  ^                        the beginning of the string
----------------------------------------------------------------------
  (                        group and capture to \1:
----------------------------------------------------------------------
    .+                       any character except \n (1 or more times
                             (matching the most amount possible))
----------------------------------------------------------------------
  )                        end of \1
----------------------------------------------------------------------
  _                        '_'
----------------------------------------------------------------------
  [^_]+                    any character except: '_' (1 or more times
                           (matching the most amount possible))
----------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------
&lt;/code&gt;
&lt;br /&gt;
or a little more tersely. Match any string that contains at least one character before and one character after the last underscore that appears in the string.
&lt;p&gt;-enlil</field>
<field name="root_node">
548901</field>
<field name="parent_node">
548901</field>
</data>
</node>
