加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式模式解释

发布时间:2020-12-14 05:38:29 所属栏目:百科 来源:网络整理
导读:我对正则表达式相当新,我最近在perl脚本中使用了一个正则表达式,我无法弄清楚: $groups= qr/(([^()]+|(??{$groups}))*)/; 任何帮助,将不胜感激! 解决方法 好吧,如果你扩展它: $groups= qr/ ( # match an open paren ( ( # followed by [^()]+ # one or
我对正则表达式相当新,我最近在perl脚本中使用了一个正则表达式,我无法弄清楚:

$groups= qr/(([^()]+|(??{$groups}))*)/;

任何帮助,将不胜感激!

解决方法

好吧,如果你扩展它:

$groups= qr/
  (                 # match an open paren (
    (                # followed by
      [^()]+         # one or more non-paren character
    |                # OR
      (??{$groups})  # the regex itself
    )*               # repeated zero or more times
  )                 # followed by a close paren )
/x;

你会得到一个优雅的递归方法来找到平衡的括号:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读