正则表达式突出显示错误的词,如 Hell«o»
并忽略正确的词 «Hello»
或 Hello
,
所以,我的问题对于我的 javascript 代码来说工作正常,但是当我为 php 尝试它时它也突出显示了字符串,这不应该:
- '«这是销售点»';
这是我的正则表达式:https://regex101.com/r/SqCR1y/14
PHP 代码:
$re = '/^(?:.*[[{(«][^\]})»\n]*|[^[{(«\n]*[\]})»].*|.*\w[[{(«].*|.*[\]})»]\w.*)$/m';
$str = '«This is the point of sale»';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
//输出
array(1) {
[0]=>
array(1) {
[0]=>
string(29) "«This is the point of sale»"
}
}
预期:空数组
jsfiddle在这里,工作正常
提前致谢
最佳答案
您没有使用正确的模式。试试这个:
$re = '/^
(?:
\([^)\n] | [^(\n]*\). |
\[[^]\n] | [^[\n]*\]. |
{[^}\n] | [^{\n]}.* |
«[^»\n] | [^«\n]*». |
.?\w[[{(«]. | .?[\]})»]\w.
)
$/mxu';
关于php preg_match_all 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44061157/