<?xml version="1.0" encoding="windows-1252"?>
<node id="354733" title="Re: RE: Quantifiers in regular expressions" created="2004-05-19 15:59:49" updated="2005-07-27 06:46:11">
<type id="11">
note</type>
<author id="121706">
ninja-joe</author>
<data>
<field name="doctext">
Here's a simple modification to the example code that will show what the regex matched when you typed it in:

&lt;code&gt;
#!/usr/bin/perl
while(&lt;&gt;) {
     chomp; # chomp so this next output is pretty.
            # newlines aren't discarded when you &lt;&gt;
     print "\"$1\" was matched out of \"$_\"" if m/(your_pattern)/;
}
&lt;/code&gt;
Be sure to include the parenthesis around the entire regex that way it will save what it matches in $1.&lt;br&gt;&lt;br&gt;


Do recall that while the regex operators are greedy by default you can suffix them with ? and they'll go to nongreedy.

An example:
&lt;code&gt;
#!/usr/bin/perl

while(&lt;&gt;) {
        chomp;
        print "\"$1\" was matched out of \"$_\"\n" if m/(\w{5}?)/;
}
&lt;/code&gt;
This will match "mywor" out of "myword"&lt;br&gt;&lt;br&gt;

Have fun regexing.</field>
<field name="root_node">
967</field>
<field name="parent_node">
8619</field>
</data>
</node>
