将递归与小组递归

发布于 2025-02-10 03:09:51 字数 306 浏览 2 评论 0原文

我不确定是否有任何正则魔术可以做到这一点:

foo(f1, f2()) = bar { b1, b2 {}} //match all of this
foo(f3) // dont match this
bar{b3} // dont match this

如果包含此模式,我要做的就是捕获整个行:

  \ w+\((?:[^()] |(括号上的递归))*\)\ s*= \ s*= \ s*\ w+{(?卷曲支架上的递归)*}
 

I am not certain if there's any regex magic that can do this:

foo(f1, f2()) = bar { b1, b2 {}} //match all of this
foo(f3) // dont match this
bar{b3} // dont match this

what I am trying to do is capture an entire line if it contains this pattern:

\w+\((?:[^()]|(?RECURSION ON PARENTHESES))*\)\s*=\s*\w+{(?:[^{}]|(?RECURSION ON CURLY BRACKETS))*}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴情 2025-02-17 03:09:51

您可以使用 regex subroutines

\w+\s*(\((?:[^()]++|(?-1))*\))\s*=\s*\w+\s*({(?:[^{}]++|(?-1))*})

请参阅 REGEX DEMO

详细信息

  • \ w+ - 一个或多个单词chars
  • \ s* - 零或更多whitespaces
  • (\((((?:[^^^)) ()++ |(? - 1))*\)) - 配对嵌套括号之间的子弦
  • \ s*= \ s* - a =用零或更多的whitespaces包围的字符
  • \ w+\ s* - 一个或多个单词chars,零或更多whitespaces
  • ({(? 1))*}) - 配对嵌套卷曲括号之间的子字符串。

注意(?1)递归最新的捕获组模式。

You can use regex subroutines:

\w+\s*(\((?:[^()]++|(?-1))*\))\s*=\s*\w+\s*({(?:[^{}]++|(?-1))*})

See the regex demo.

Details:

  • \w+ - one or more word chars
  • \s* - zero or more whitespaces
  • (\((?:[^()]++|(?-1))*\)) - a substring between paired nested parentheses
  • \s*=\s* - a = char enclosed with zero or more whitespaces
  • \w+\s* - one or more word chars, zero or more whitespaces
  • ({(?:[^{}]++|(?-1))*}) - a substring between paired nested curly braces.

Note the (?-1) recurses the latest capturing group pattern.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文