Perl is not really thinking [3,] is {3,}

Let's step through the regex, and see why it matches.

/^ #Match at the beginning of the string ( #begin $1 [a-zA-Z_)[3,] #A character class .* #Any number of characters ? #Minimal match the .* ) #End $1 : #Match a colon ( #Begin $2 .* #Match until end of line )/x #End $2 and the match

Alright, the large character class will match one letter that is upper or lower case, and underscore, an open paren, a open bracket, a 3, or a comma. The open bracket does not confuse Perl into thinking we have a new character class (This can be tested by replacing 'Time' with '[ime'). This huge class matches the upper case 'T' in $line.

The dot star matches the 'ime' up until the colon. In this specific case, the minimal match construct doesn't do anything. (Test by deleting it). This all stores the word 'Time' in $1.

The colon is matched and not saved. So we begin saving after the colon, and we just match until the end of the line - that's '174657', which gets stored in $2.

Then we just print those things out. As for forming a regex which actually matches the format you want, I don't quite understand what that format is (your comment is unclear to me).

Hope this helps.

Cheers,
Erik

In reply to Re: Strange regex-behaviour by erikharrison
in thread Strange regex-behaviour by strat

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.