考虑以下值:
$format = ',0'; // Thousand separators ON, no decimal places
$format = '0'; // Thousand separators OFF, no decimal places
$format = '0.000'; // Thousand separators OFF, 3 decimal places
$format = ',0.0'; // Thousand separators ON, 1 decimal place
$format
是否以','为前缀。这告诉我启用了千位分隔符。我设法匹配表达式(这不是很难),但我想要做的是提取单个匹配,以便我知道是否有','找到,以及有多少个零等等...
这是我到目前为止所做的:
preg_match_all('/^\,?[0]?[\.]?([0])+?$/',$value['Field_Format'],$matches);
答案 0 :(得分:1)
我会使用不同的正则表达式并将子结果放入命名组中:
if (preg_match(
'/^
(?P<thousands>,)? # Optional thousands separator
0 # Mandatory 0
(?: # Optional group:
(?P<decimal>\.) # Decimal separator
(?P<digits>0+) # followed by one or more zeroes
)? # (optional)
$ # End of string/x',
$subject, $regs)) {
$thousands = $regs['thousands'];
$decimal = $regs['decimal'];
$digits = $regs['digits'];
}