将递归与小组递归
我不确定是否有任何正则魔术可以做到这一点:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 regex subroutines :
请参阅 REGEX DEMO 。
详细信息:
\ w+
- 一个或多个单词chars\ s*
- 零或更多whitespaces(\((((?:[^^^)) ()++ |(? - 1))*\))
- 配对嵌套括号之间的子弦\ s*= \ s*
- a=
用零或更多的whitespaces包围的字符\ w+\ s*
- 一个或多个单词chars,零或更多whitespaces({(? 1))*})
- 配对嵌套卷曲括号之间的子字符串。注意
(?1)
递归最新的捕获组模式。You can use regex subroutines:
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.