#!/usr/bin/perl -- use strict; use warnings; use Regexp::Assemble; my( @usd ) = ( q[$0,000.00], q[$0000], q[$999], q[$1,000], q[$1,000.00], q[$2,000], q[$9,000], q[$10,000], q[$10,00000.00], q[$100,000], q[$999,000], q[$1,000,000], q[$1,234,567,890.00], ); sub refit { my( $re ) = Regexp::Assemble->new; $re->add(shift) while @_; $re=$re->re; print "\n\n$re\n"; for my $usd ( @usd ){ no warnings 'uninitialized'; printf "[ %20s ]= %d\n", $usd, $usd =~ $re; } print '-' x 50 , "\n\n"; } refit( '^\$1,?\d\d\d(?:\.\d\d)?$', # $1,000 $1,000.00 '^\$[2-9],?\d\d\d(?:\.\d\d)?$', # $2,000 $9,000 '^\$\d\d,?\d\d\d(?:\.\d\d)?$', # $10,000 $99,000 '^\$\d\d\d,?\d\d\d(?:\.\d\d)?$', # $100,000 $999,000 '^\$\d,?(?:\d\d\d,?)+\d\d\d(?:\.\d\d)?$', # $1,000,000 $1,234,5 +67,890.00 ); refit( '^\$1,?\d\d\d(?:\.\d\d)?$', # $1,000 $1,000.00 '^\$[2-9],?\d\d\d(?:\.\d\d)?$', # $2,000 $9,000 '^\$\d\d[\d,]*?\d\d\d(?:\.\d\d)?$', # $10,000 $10,00000.00 ); __END__ (?-xism:^\$(?:\d(?:,?(?:\d\d\d,?)+|\d?\d,?)|(?:[2-9]|1),?)\d\d\d(?:\.\ +d\d)?$) [ $0,000.00 ]= 0 [ $0000 ]= 0 [ $999 ]= 0 [ $1,000 ]= 1 [ $1,000.00 ]= 1 [ $2,000 ]= 1 [ $9,000 ]= 1 [ $10,000 ]= 1 [ $10,00000.00 ]= 0 [ $100,000 ]= 1 [ $999,000 ]= 1 [ $1,000,000 ]= 1 [ $1,234,567,890.00 ]= 1 -------------------------------------------------- (?-xism:^\$(?:(?:[2-9]|1),?|\d\d[\d,]*?)\d\d\d(?:\.\d\d)?$) [ $0,000.00 ]= 0 [ $0000 ]= 0 [ $999 ]= 0 [ $1,000 ]= 1 [ $1,000.00 ]= 1 [ $2,000 ]= 1 [ $9,000 ]= 1 [ $10,000 ]= 1 [ $10,00000.00 ]= 1 [ $100,000 ]= 1 [ $999,000 ]= 1 [ $1,000,000 ]= 0 [ $1,234,567,890.00 ]= 0 --------------------------------------------------

In reply to Re: matching USD amounts by Anonymous Monk
in thread matching USD amounts by Anonymous Monk

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.