【发布时间】:2017-11-10 01:41:47
【问题描述】:
我将每个单词与相同的段落单词进行匹配。
更新 1:我意识到仅仅接受你需要的标点并不能解决这个问题。
示例 'hello-' 和 'hello' 被视为单独的单词。
有没有办法去除单词前后的标点符号和单独的标点符号?只允许在单词中使用标点符号。
$string="_ - – hello’ hello' hello, hello- world. he,llo hello-world hello_world hel-lo-world hello9world";
输出应该是
hello hello hello hello world he,llo hello-world hello_world hel-lo-world hello9world
只有单词或单词中的标点符号
更新 2:如果只有单词或单词中的标点符号,十进制数会有问题。
1.0 还是可以的,.1 作为前后标点去掉,会变成 1 而不是 0.1
更新 3:接受 word 中的标点符号, 以字母或数字开头或结尾的子字符串会有问题。 20岁会变成'20-''岁'。
谢谢米克马克萨。
【问题讨论】:
-
你为什么不匹配
[^\s]+而不是空格,以及任何你不想要的东西 -
那我不明白你在做什么。
-
know this word occur how many timessubstr_count如果你知道字符串呢? php.net/manual/en/function.substr-count.php