m/\s(\d+(?:\.\d+)?)(?:\s*ms)/

If the match is successful (be sure to check), the numeric value will be in $1.

This matches one or more numeric digits, followed optionally by a decimal point and one or more digits, followed by an optional space, followed by "ms" (milliseconds). The space-"ms" part is not strictly necessary, but could help if there's a possibility of two sets of numbers ending up in the string somehow, plus IMHO, it can make an RE more human readable if there is some predictable anchor text in there for a human eye to catch.

Update: Note that this RE will accept numbers that look like "1", or "1.0", but not ".1". I did that on purpose, assuming that "0.1" is how decimal milliseconds would be represented. It wouldn't be too hard to tweak it to accept ".1" as well, but probably unnecessary. This particular RE will also reject numbers that have more than one decimal point (as in 198.60.22.2), which really isn't a number anyway. That too is by design. Oh, and negative numbers aren't accepted. Add an optional hyphen to the beginning if you want them. ;) Enjoy!


Dave


In reply to Re: How do I extract the value from this string...? by davido
in thread How do I extract the value from this string...? by evert

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.