打破带有可选空格和数字以及点的字符串

时间:2016-07-08 08:05:38

标签: php regex

尝试从(可选空格)数字和点打破字符串。

$string = "1.1Kumar/Sandeep MR*T0148.4801 12.23Pal/Sandeep MR*T643.948";
$regex1 = "/(\s*[0-9]+\.)/";
$regex2 = "/(?<=\s)[0-9]+\./";

我需要打破 1。 12。。 第一个正则表达式给出:

Array
(
    [0] => 
    [1] => 1Kumar/Sandeep MR*T
    [2] => 4801
    [3] => 23Pal/Sandeep MR*T
    [4] => 948
)

第二个正则表达式给出:

Array
(
    [0] => 1.1Kumar/Sandeep MR*T0148.4801 
    [1] => 23Pal/Sandeep MR*T643.948
)

我想得到:

Array
(
    [0] => 1Kumar/Sandeep MR*T0148.4801 
    [1] => 23Pal/Sandeep MR*T643.948
)

1 个答案:

答案 0 :(得分:3)

对于您的示例字符串,这将起作用:

\b\d+\.

Regular expression visualization

Debuggex Demo

确保在数字部分之前有单词中断。 (行的开头或空格)