The behavior you're describing certainly sounds weird to me. I suspect it's your [^\d] and [^ ] groups, which are goofy. I changed them as described below and your regular expression worked great for me.

Note that items like \d and [ ] (perhaps illegal, but I know what you're doing and this is equivalent to \s) have opposites: \D (non-digits) and \S (non-spaces).

In your case here, your regular expression could be better written like:

/(\d+\S+)\D+(\d+): (.*)$/
Perhaps someone else has a better optimization, but this will essentially start your search on the first number, continue for the rest of that "field", and then match non-numbers until it gets your 2nd numeric, following up with everything else in $3. Modify to taste.

You may also want to consider using split to break your line up into fields separated by spaces. The only processing you'd have to do at that point is to get rid of the colon following your last numeric.

Note: Code samples are for conceptual use only and generally are not meant to be cut/pasted into a production application. Always 'use strict', have a thorough understanding of the code you use, and check the return values of functions and handle errors according to your needs. - Fastolfe

In reply to Re: Matching (non)spaces in regex? by Fastolfe
in thread Matching (non)spaces in regex? by Guildenstern

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.