Solved

need to extract price range from a text

Posted on 2010-11-21
3
435 Views
Last Modified: 2012-05-10
i need to extrac the price range like $XX-$XXX USD, from text. the X may be single digit or many digits to follow. any help with this.
0
Comment
Question by:rajccs
3 Comments
 
LVL 13

Accepted Solution

by:
dsmile earned 500 total points
ID: 34182625
Try this
<pre>

<?php

$pattern = '/(\$[0-9]+-\$[0-9]+ USD)/';

echo $string = <<< TXT

dummy text dummy text dummy text $112-$1324 USD dummy text dummy text 

dummy text dummy text $1312-$13624 USD dummy text dummy text dummy text $14412-$13244 USD dummy text dummy text 

dummy text $1012-$13244 USD dummy text dummy text dummy text $112-$13242 USD dummy text dummy text 

TXT;

preg_match_all($pattern, $string, $result);

print_r($result);

?>

Open in new window

0
 
LVL 10

Expert Comment

by:jfromanski
ID: 34182723
Try dsmile code, but with:

$pattern = '/(\$[0-9]+)-(\$[0-9]+)/';

this will split every $XX-$XXX into lower and upper boundary
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34193694
And:

$pattern = '/(\$[0-9.]+)-(\$[0-9.]+)/';

if you want to allow cents...
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now