These are untested, and still have limitations, on which I'll elaborate in a moment:

The limitations: With respect to phone numbers, if the number is something like 1-800-GO-FISH you're out of luck. Also, it has to be a USA number of seven or ten, or eleven (including the leading 1) digits.

With respect to the pricing, you have to have something in front of the optional decimal place, and you have to have a dollar sign. Otherwise it will fail to match. Oh, and if the price is "One Million Dollars!" you won't capure it, since it's not numeric.

There are probably other limitations as well.

You should also consider looking at Number::Phone::US. Here's a snippet:

use Number::Phone::US qw/is_valid_number/; print "Phone: $number\n" if is_valid_number( $number );

Also, be sure to have a look at Regexp::Common::number. You might be able to either make use of it, or glean some knowledge from its source code.

UPDATE: I've had time to test and rework them a little now. I fixed the missing ')' in the phone number RE, and added some logic to invalidate prices that have more than two digits to the right of the decimal point.

PS: I recommend passing my RE's through YAPE::Regex::Explain so that you can see a detailed description of what they do. It's pretty easy to use.


Dave


In reply to Re: pricing and phone number regexes by davido
in thread pricing and phone number regexes by coldfingertips

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.