我想用正则表达式提取下划线之后的每个数字和字符。我试过'_'d{1,3}
,但它根本不起作用。
下面是我需要操作的链的示例:R_31_1_35_6a
。
这是我想要的结果:
array('31', '1', '35', '6a');
您可以使用explosion来用下划线分隔字符串:
$string = "R_31_1_35_6a";
$result = explode('_', $string);
然后你可以删除第一个条目,在这个例子中是'R':
array_shift($result);
返回预期结果:
var_dump($result);
看看explode
。
$string = "R_31_1_35_6a";
$cleanedString = strstr("_", $string);
$result = explode('_', $cleanedString);
print_r($result); // Ignore the first (zeroth) element as it's the prefix value