- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
正则表达式突出显示错误的词,如 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/
我有这个正则表达式 {{([ a-zA-Z0-9_\-]+)\s*(?:\[([ a-zA-Z0-9_\-]+)\]\s*)*}} 我需要匹配如下字符串: {{word with spaces}} {
我有这个子模式: 它的结果是这样的输出: php test.php Array ( [0] => Array ( [0] => d
你好我想提取链接 我想要一个正则表达式给我/portal/clients/show/entityId/2121最后2121的数字在其他链接中不同有什么想法吗? 最佳答案 Simple PHP HTML
我试图提取所有 img 来自 HTML 字符串的标签。看代码 $d1 = file_get_contents("http://itcapsule.blogspot.com/feeds/post
我正在尝试为我们的防火墙创建报告功能。 防火墙规则以 json 格式存储。 这是字符串的示例。 [{"id":1,"enabled":true,"description":"TEMP","matche
我需要从文本 block 中提取一组预定义的主题标签,然后提取紧随其后的数字(如果有)。例如。我需要从“带有#other30 标签的测试字符串”中提取 30。我认为 preg_match_all 是正
我正在尝试从可能很大的文本中提取 ID,我错过了什么? preg_match_all('/(ID\s\d+)/', "ID 20380843, ID 20675712", $matches); pr
我正在尝试抓取 html 并抓取 之间的项目标签。由于某种原因( ),某些标签以大写形式出现,并且被我的模式忽略。我如何告诉我的模式忽略大小写。 我当前的模式是: preg_match_all("
我有一个从另一个网站读取数据的脚本,但我希望该脚本从下向上而不是从上向下获取数据。 例如,如果结果是: 结果#1结果#2结果#3 我想先得到#3,然后是2,然后是1。目前它得到的是1,然后是2,然后是
我有一个网址: https://my.site.com/u/0/ac?export=download&confirm=45vy&id=qNhdhk1jejhXLexLpY3RiDY2o
在使用正则表达式时遇到问题(它们不是我的强项)。我试图匹配 {{ 和 }} 之间的所有字符串,但如果一组括号出现在同一行上,则会将其视为单个匹配...示例: $string = " Hello,
我有一个始终遵循以下格式的字符串: This Fee Name : * Fee Id * Fee Amount $* is required for this activity 例子: Thi
我在使用 php (preg_match_all) 中的正则表达式时遇到了一些问题。 我正在使用以下代码查找由 <>: 封装的电子邮件,即: preg_match_all(":", $body,$ma
我有这个脚本可以从另一个网站读取数据,但我希望脚本从下到上而不是从上到下获取数据。 例如如果结果是: 结果 #1结果 #2结果 #3 我想先得到#3,然后是 2,然后是 1。目前它是 1,然后是 2,
我有一个网址: https://my.site.com/u/0/ac?export=download&confirm=45vy&id=qNhdhk1jejhXLexLpY3RiDY2o
我正在尝试获取点后的值,并且我想获取所有这些点(每个都是它们自己的键/值)。 以下是我正在运行的内容: $string = "div.cat.dog#mouse"; preg_match_all("/
这个问题已经有答案了: "Regular Expression is too large" error in PHP (3 个回答) 已关闭 3 年前。 我该如何改进以下preg_match_all模
我不知道为什么,但是当我执行脚本时,它没有正确显示这些行。它只是返回可变行的最后一行,下面没有输入。我是不是忽略了什么? 文件1: 06BAH TOI00123-11-134-B
我想检查 'n' 分解这个字符串: {$gallery#pager/collectionName/imageName/manual/no_effect/foo1/foo2/.../fooN} 到: v
我尝试先阅读其他问题,但没有发现任何有用的东西。 我在自己的 PC 上有一个装有 PHP 5.3.28 和 PHP 5.4.7 的开发服务器。 $string = 'Match this'; preg
我是一名优秀的程序员,十分优秀!