【发布时间】:2016-05-11 18:12:02
【问题描述】:
我只想返回不符合此条件的数字。 标准的示例是 Apt 2、Department 4 等
下面的代码是我一直在尝试的,但它不起作用。 结果应该与输出的结果相同 preg_match_all('!\d!', $string, $matches);
我希望有一个 2 3 4 4 5 4 5 2 3 2 作为输出的数组。它应该不包括 Apt 92 的号码和 Block 5 的号码。
$string = "23 St John Apt 92 rer 4, Wellington Country Block 5 No value test 4545 tt 232";
preg_match_all('!\d(^((?:Apartment|Apt|Block|Department|Lot|Number|Villa)\s*)([0-9]+))!', $string, $matches);
var_dump($matches);
【问题讨论】:
-
你完全误解了字符类。你期望什么输出?
标签: regex preg-replace preg-match preg-match-all