Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 正则表达式:将文本拆分为单词、空格和逗号:单引号缩写除外_Php_Regex_Preg Split - Fatal编程技术网

Php 正则表达式:将文本拆分为单词、空格和逗号:单引号缩写除外

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){

我需要将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){
    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