this is my patten: (TABLE[0-9]+)\(((?<=\()(.*?)(?=\)))[(?=\))\)]
这是我的彭定康:(表[0 - 9]+)\(((? < = \()(. * ?)(? = \)))((? = \))\]
this is the string i'm looking at: (TABLE3(1.6+TABLE1(2)))*TABLE2(1)*TABLE11(1)*(1.19017735023328)
这是我正在查看的字符串:(表3(1.6+表1(2)))*表2(1)*表11(1)*(1.19017735023328)
what i get are:
我得到的是:
i need the first one to be: TABLE3(1.6+TABLE1(2))
我需要第一个为:TABLE3(1.6+TABLE1(2))
how can i do that?
我怎么做呢?
3
Use a balancing group construct after TABLE[0-9]+
:
使用表[0-9]+后的平衡组结构:
TABLE[0-9]+\((?>[^()]|(?<o>)\(|(?<-o>)\))*(?(o)(?!))\)
See the regex demo.
查看演示正则表达式。
Details
细节
TABLE[0-9]+
- matches TABLE
and 1+ digits\(
- an open (
(?>[^()]|(?<o>)\(|(?<-o>)\))*
- zero or more occurrences of
[^()]
- any char but (
and )
|
- or(?<o>)\(
- a (
(and increments the stack of the o
group)|
- or(?<-o>)\)
- a )
(and decrements the stack of the o
group)(?(o)(?!))
- fail the match (triggers backtracking) if Group o
stack is not empty\)
- a )
. 本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2017/08/28/f036101de6ff2213a4093b1221231905.html。