I'm trying to create a regex, based off running another set of regexs on a given string.
And basically dynamically come up with a shortened regex that will match the original string.

The problem is i'm seeing an odd behavior.

#!/usr/bin/perl -w my $string = '/path/file.htm?849578345908543095364b892a898374aff849000 +1289384add90e93448a839457582993cde90239a90459c3849aa8374f783477346723 +f38923487dd8923847a892837f783746543ff89283a439823cd948399134452&acces +s_rights=1&mn_ord=yes&session_id=84'; $string =~ s/[^ a-zA-Z0-9_=&\-]/sprintf("\\%s", $&)/eg; # #escape char +s print "$string\n"; #debug $string =~ s/([A-Za-z0-9][^&\/\.]){10,}/sprintf(".*", $&)/eg; $string =~ s/([0-9]){2,}/sprintf("\\d+", $&)/eg; print "\n$string\n";#debug


The problem is it returns
\/path\/file\.htm\?.*2&access_rights=1&mn_ord=yes&session_id=\d+
I'm having difficultly understanding why it wouldn't return
\/path\/file\.htm\?.*&access_rights=1&mn_ord=yes&session_id=\d+

In reply to help in understanding odd regex match by jaco

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.