我正在分解的字符串中有这些类型的可能内容:
$string = "$100 USD per year"
$string = "$100USD per year"
$string = "100 USD per year"
$string = "100EUR per year"
$string = "€100EUR per year"
$string = "€100 EUR per year"
这是我正在使用的正则表达式(它适用于 Expresso):
$pattern = "/\$?(\d+\.\d+)(\w{0,3})\s(.*)/i";
基本上,我希望最终结果是一个如下所示的数组:
$arr[0] = "$100" // the "$" optional, also number might be integer or decimal
$arr[1] = "USD";
$arr[2] = "per year";
这是我正在运行但无济于事的示例 PHP 代码:
<?php
$content = "$99.37CAD per year";
$pattern = "/\$?(\d+\.\d+)(\w{0,3})\s(.*)/i";
$myArr = preg_split($pattern, $content);
echo "<pre>";
var_dump($myArr);
echo "</pre>";
?>
输出是:
bool(false)
有人可以指出我正确的方向吗?