我需要匹配以下字符串:
27,B661|27,071315S|27,B2843|2,355516|27,ASB844|27,H994|28,073126|
基本上,我想在逗号之后但在垂直条之前匹配确切的文本。所以'B661'会匹配。仅'B66'是不匹配的。似乎无法弄清楚这一点!
答案 0 :(得分:1)
@ {Wiktor说,explode()
两次(!);
<?php
$string = "27,B661|27,071315S|27,B2843|2,355516|27,ASB844|27,H994|28,073126|";
$arr = explode("|", $string);
foreach ($arr as $item) {
list($key, $value) = explode(",", $item);
echo "$key: $value\n";
}
?>
或使用正则表达式:
(?<=,)\w+(?=|)