php - 正则表达式,preg_match_all模式中的反向引用问题

标签 php regex preg-match-all backreference

我想知道这里的反向引用是什么问题:

preg_match_all('/__\((\'|")([^\1]+)\1/', "__('match this') . 'not this'", $matches);

它应该与__('')之间的字符串匹配,但实际上它返回:
match this') . 'not this

有任何想法吗?

最佳答案

使您的正则表达式不满意:

preg_match_all('/__((\'|")([^\1]+)\1/U', "__('match this') . 'not this'", $matches)

关于php - 正则表达式,preg_match_all模式中的反向引用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6050427/

相关文章:

php - 如何找到以下情况的联合查询

regex - 匹配关键字数组中的属性字符串

regex - 如何处理 Perl 正则表达式中的每个 ASCII 字符(包括正则表达式特殊字符)?

mysql - MySQL Regexp 是否支持 Unicode 匹配

php - 准备好的语句 - 行数

php - Laravel Eloquent 在父表中有很多条件

php - 使用 php 正则表达式查找包含单词的整行

php - 正则表达式 匹配字符串

php - 使用 w.* 的正则表达式模式不匹配以外来字符开头的文本,例如 Ä

php - 在solr结果中隐藏路径(id)