Php 正则表达式:将文本拆分为单词、空格和逗号:单引号缩写除外
我需要将Unicode文本拆分为数组,保留空格和标点符号。问题:我需要将“That's”或“till”等缩写作为单个术语 我来的远了:Php 正则表达式:将文本拆分为单词、空格和逗号:单引号缩写除外,php,regex,preg-split,Php,Regex,Preg Split,我需要将Unicode文本拆分为数组,保留空格和标点符号。问题:我需要将“That's”或“till”等缩写作为单个术语 我来的远了: $String = "'till I got this help, I could not do by myself!"; $arr = preg_split("/(\s|\W)/u", $String, -1, PREG_SPLIT_DELIM_CAPTURE |PREG_SPLIT_NO_EMPTY); foreach ($arr as $word){
$String = "'till I got this help, I could not do by myself!";
$arr = preg_split("/(\s|\W)/u", $String, -1, PREG_SPLIT_DELIM_CAPTURE |PREG_SPLIT_NO_EMPTY);
foreach ($arr as $word){
echo "<span class=\"Term $word\">".$word."</span>";
}
$String=““在我得到这个帮助之前,我不能自己做!”;
$arr=preg_split(“/(\s |\W)/u“,$String,-1,preg_split_DELIM_CAPTURE | preg_split_NO_EMPTY);
foreach($arr作为$word){
回声“$word.”;
}
- [0]=>'
- [1] =>直到
- [2] =>
- [3] =>我
- [4] =>
- [5] =>得到
- [6] =>
- [7] =>这个
- [8] =>
- [9] =>帮助
- [10] =>,
- [11] =>
- [12] =>我
- [13] =>
- [14] =>可以
- [15] =>
- [16] =>不是
- [17] =>
- [18] =>做
- [19] =>
- [20] =>通过
- [21]=>
- [22]=>我自己
- [23]=>李>
检查
\W\B
/(\s |[^\W'])/u
@revo bingo!这救了我一个星期。我需要找到一个好的正则表达式资源来学习它。除了quote在今天的任务末尾时返回到绘图板。为了避免歧义,请使用这个/(\s|[^\w']|\B'\B)/u