例如我有这样的句子:
$text = "word, word w.d. word!..";
我需要这样的数组
Array
(
[0] => word
[1] => word
[2] => w.d
[3] => word".
)
我对正则表达式很陌生..
这是我尝试过的:
function divide_a_sentence_into_words($text){
return preg_split('/(?<=[\s])(?<!f\s)\s+/ix', $text, -1, PREG_SPLIT_NO_EMPTY);
}
这个
$text = "word word, w.d. word!..";
$split = preg_split("/[^\w]*([\s]+[^\w]*|$)/", $text, -1, PREG_SPLIT_NO_EMPTY);
print_r($split);
有效,但我有第二个问题,我想用 mu 正则表达式写列表“wd”是特例。例如,这个词是我的列表“wd”、“先生”、“博士”。
如果我要接受文字:
$text = "单词,博士单词 wd 单词!..";
我需要数组:
Array (
[0] => word
[1] => dr.
[2] => word
[3] => w.d
[4] => word
)
对不起英语不好...