in reply to Re^3: Parsing Regex
in thread Parsing Regex

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

Replies are listed 'Best First'.
Re^5: Parsing Regex
by deMize (Monk) on Sep 23, 2009 at 14:56 UTC
    Please delete this reply -- I was wrong -- it put me back to square 1