So it didn't work, here's what's interesting:
Code:
$line =~ m/(.*?)(\d+\/\d+\/\d+)?\s*(.*)/; print "Input : $line"; print "Output \$1: -$1-\n"; print "Output \$2: -$2-\n"; print "Output \$3: -$3-\n\n";
Results:
Input : 301 S. MAPLE STREET Output $1: -- Output $2: -- -utput $3: -301 S. MAPLE STREET Input : 09/09/2009 301 S. MAPLE STREET Output $1: -- Output $2: -- -utput $3: -09/09/2009 301 S. MAPLE STREET
I included the "neat" flag (x), but decided to take it away. For all purposes, the above should be the same. Note: I put the first "ungreedy capture anything" (.*?) in $1 for debugging purposes. The results are interesting.

One interesting thing is the termination '-' that is being outputted to the front of the line, which makes it look like more is going on here than meets the eye.

What I really need is a lookbehind. Note: even if I get rid of the first .*, there are still problems.

The same thing is throwing it off (the date capture). If I remove or change the '?' to a '+', then it works for the second input, but not the first input. The first input reuses $1 and $2 from a previous regex (not shown) $3 empty; hence, it doesn't match at all.

Example:
Input : 301 S. MAPLE STREET Output $1: -000001- -utput $2: - JOHN SMITH, III Output $3: -- Input : 09/09/2009 301 S. MAPLE STREET Output $1: - - Output $2: -09/09/2009- -utput $3: -301 S. MAPLE STREET

In reply to Re^4: Parsing Regex by deMize
in thread Parsing Regex by deMize

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.