【问题标题】:Regular Expression explanation: (?>[^<>]+)正则表达式解释:(?>[^<>]+)
【发布时间】:2011-04-05 22:45:58
【问题描述】:

请问/(?&gt;[^&lt;&gt;]+)/,应该如何解释? (PHP 正则表达式引擎)

谢谢。

【问题讨论】:

  • 我不认为这是一个有效的正则表达式。
  • ? 在那里有效。它是一个原子团。
  • +1 有趣,没听说过。我的正则表达式测试器抛出了一个错误。
  • 我不明白它在像/(?&gt;[^&lt;&gt;]+)/这样的正则表达式中有什么用处??
  • (?&gt;[^&lt;&gt;]+)[^&lt;&gt;]++ 完全相同。

标签: php regex pcre


【解决方案1】:
(?>        # I had to look this up, but apparently this syntax prevents the regex
           # parser from backtracking into whatever is matched in this group if 
           # the rest of the  pattern fails
   [^<>]+  # match ANY character except '<' or '>', 1 or more times. 
         ) # close non-backtrackable group.

对于一次性模式感兴趣的任何人,请查看http://www.regextester.com/pregsyntax.html 中的Once-only subpatterns 部分

【讨论】:

  • 如果你使用 Perl 正则表达式,你应该经常咨询the appropriate documentation.
  • @tchrist 他在问 PHP 虽然
  • 你认为 preg_ 函数的名字来源于哪里?
  • 他说的是 PCRE,所以最准确的文档应该是pcre.org/pcre.txt
  • 好吧,但我使用的站点中提到的 PHP 实现的差异呢?
猜你喜欢
  • 2013-01-06
  • 1970-01-01
  • 2012-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
  • 1970-01-01
相关资源
最近更新 更多