我有以下代码,我需要对其进行调整,以获得所需的echo。
<?php
$price = "A1,500.99B";
$pattern = '/([\d,]+\.)(\d+)(.*)$/'; // This is something that I need to change, in order to get the desired result
$formatted_1 = preg_replace($pattern, '$1', $price);
$formatted_2 = preg_replace($pattern, '$2', $price);
$formatted_3 = preg_replace($pattern, '$3', $price);
$formatted_4 = preg_replace($pattern, '$4', $price);
echo $formatted_1; // Should give A
echo $formatted_2; // Should give 1,500
echo $formatted_3; // Should give 99
echo $formatted_4; // Should give B
?>
我知道我应该在$pattern内添加另一个( ),并调整上面的$pattern,但我不知道该怎么做。
谢谢。