我有以下字符串:123j12i need 2
我想将其拆分,以便最终得到123j12
和i need 2
。
这是我到目前为止所尝试的:
$mssg = "123j12i need 2";
Preg_match("/.{6}(\d+)/", $mssg, $match);
echo $match[0];
#123j12 expected
echo $match[1];
#i need 2 expected
任何帮助都将不胜感激。
答案 0 :(得分:0)
试试这个
$str = '123j12i need 2';
$str = preg_replace('/(\w+)(\w\sneed\s[0-9])/', '\1 \2', $str);
echo $str;
输出
123j12 i need 2
看到它here
答案 1 :(得分:0)
此代码
$mssg = "123j12i need 2";
$match = preg_split("/(?<=123j12)/", $mssg);
var_dump($match);
给出
array(2) {
[0]=>
string(6) "123j12"
[1]=>
string(8) "i need 2"
}