Link to home
Start Free TrialLog in
Avatar of interclubs
interclubs

asked on

Help with Regex

I have the following regular expression, which I am trying to use to extract dollar amounts. I want it to only pull out values that either have a decimal point followed by 2 digits, or a dollar sign.

So in the below example, these would not be a match: #2343434 222 123-2333 $12.0
<?php
$text = '#2343434 222 123-2333 $12.0 $34.00 34.00 1,000.00 $3';
if(preg_match_all('/\$?\d+(?:\.\d+)?/ims',$text,$matches)){
	trigger_error(var_dump($matches, true));
}
?>

Open in new window




ASKER CERTIFIED SOLUTION
Avatar of OmniUnlimited
OmniUnlimited
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of interclubs
interclubs

ASKER

thanks!