Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I have a very complex regex that I want to do the back-referencing for the replacement...

$s =~ s/\ ((0?[1-9]|1[0-2])\/(0?[1-9]|[1-2][0-9]|3[0-1])\/(19|20)?[0-9 +][0-9](\s(((0?[0-9]|1[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?)|((0?[0-9 +]|1[0-2]):[0-5][0-9](:[0-5][0-9])?\s(AM|PM))))?)\ /\n$1\n/g;

The result is desirable when I using $1 but not $+...so I would like to ask, what is their different?

Thank you

Replies are listed 'Best First'.
Re: Confusion of the effect of $+ and $1
by igelkott (Priest) on Mar 30, 2008 at 18:30 UTC

    The simple answer is that $1 is the first match and $+ is that last match.

    What may be more helpful is to suggest that you consider using a Date module from CPAN to parse date/time rather than rely on an overly complex regex.

Re: Confusion of the effect of $+ and $1
by Anonymous Monk on Mar 30, 2008 at 18:07 UTC
    what result? Try  use re 'debug';

      Hi,

      The result is: the matched string appear in the position of $1 - where I failed with a $+: $+with give me nothing, but $1 doesn't

      Thank you