The code I used to create and use that regex (Commented) is
#!/usr/bin/perl -w my %form = ( 'searchprice' => "15001-9999999", ); my @Tests = ('$1600', ' $1,300 ', ' $1,600,000.43 ', ' $1600. ', ' $16 +00.43 '); foreach my $desc (@Tests) { print "Testing $desc\n"; my ($LowValue, $HighValue) = split("-", $form{'searchprice'}); #s +plits two values to compare desc to if ($desc =~ m/ \$ #Matches the dollar sign ( #Begins gathering the digit grouping \d{1,3},? #Grabs between 1 and 3 digits. #There must be at least one and at mo +st #3 before the first comma. [\d{3},?]* #This grabs groups of 3 digits, #and the comma after them if it exist +s \.?\d{0,2} #This grabs the final decimal point a +nd #up to two places after it if they ex +ist )#Ends the digit grouping /x #tells it to ignore whitespace ) { my ($Price) = $1; #sets $Price equal to the match in the regex $Price =~ s/,//g; #Strips out commas print "TestPrice $Price\n"; if (($LowValue <= $Price) && ($Price <= $HighValue)) { print "$desc\n"; } } else { print "No price found in $desc\n"; } print "\n"; }
The regex itself isn't quite as clean as it could be, but it works on the assumption that there is one and only one properly formatted price in each $desc.

Dave

In reply to Re: Re: Re: Search question : Price Regex by dfog
in thread Search question by SysAdm

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.