3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $prices = array(chr(8364).' 45.000,-', '45 USD', 'CHF 0,77', chr(36).' 23000', 'USD 23000', '46.000,95', '6', '4,3', chr(8364).' 45,00', chr(36).' 46foobar', chr(8364).' 45,-', chr(8364).' 45', chr(8364).' 45,00', '45 '.chr(8364), '45,- '.chr(8364), '45,00 '.chr(8364), '45.000 '.chr(8364), chr(36).' 45.000,--', chr(8364).' 4.000,00', 'hallo welt', '20.00 €'); $currencies = '(?:EUR|USD|GBP|CHF|FR|SFR|\\'.chr(8364).'|\\'.chr(36).'|\\'.chr(163).')'; $price = '(?:(?:(?:[1-9][0-9]{0,2}(?:\.|,)?)+(?:[0-9]{3})|(?:[0-9]|[1-9][0-9]{1,2}))(?:(?:\.|,)(?:[0-9]{2}|\-{1,2}))?)'; $regex = '(?:^|\s+)(?:(?:(?:'.$currencies.'\s?)'.$price.')|(?:'.$price.'(?:\s?'.$currencies.')))(?:\s+|$)'; foreach($prices as $check) { echo str_pad($check, 15, ' ', STR_PAD_RIGHT).' '.(preg_match('/'.$regex.'/i', $check, $match) ? 'matched: ' : 'did not match.').(count($match) ? $match[0] : '')."\n"; }
Output for 4.3.0 - 7.2.0
� 45.000,- matched: � 45.000,- 45 USD matched: 45 USD CHF 0,77 matched: CHF 0,77 $ 23000 matched: $ 23000 USD 23000 matched: USD 23000 46.000,95 did not match. 6 did not match. 4,3 did not match. � 45,00 did not match. $ 46foobar did not match. � 45,- matched: � 45,- � 45 matched: � 45 � 45,00 matched: � 45,00 45 � did not match. 45,- � matched: 45,- � 45,00 � matched: 45,00 � 45.000 � matched: 45.000 � $ 45.000,-- matched: $ 45.000,-- � 4.000,00 matched: � 4.000,00 hallo welt did not match. 20.00 € did not match.