【发布时间】:2020-09-09 07:00:21
【问题描述】:
正则表达式 = (位数)*(A|B|DF|XY)+(位数)+
我真的对这种模式感到困惑 我想在 PHP 中分隔这个字符串,有人可以帮助我 我的输入可能是这样的
- A1234
- B 1239
- 1A123
- 12A123
- 1A 1234
- 12 123
- 1234 B 123456789
- 12 XY 1234567890
并转换成这个
Array
(
[0] => 12
[1] => XY
[2] => 1234567890
)
<?php
$input = "12 XY 123456789";
print_r(preg_split('/\d*[(A|B|DF|XY)+\d+]+/', $input, 3));
//print_r(preg_split('/[\s,]+/', $input, 3));
//print_r(preg_split('/\d*[\s,](A|B)+[\s,]\d+/', $input, 3));
【问题讨论】:
标签: php regex string split preg-split