我试图在数据中分别查找和捕获(和)内部的所有数字,而忽略其余数字。
我的数据看起来像这样
21 [42] (12) 19 25 [44] (25 26 27) 17 (14 3) 8 1 6 (19)
所以,我要找到匹配的12
,25
,26
,27
,14
,3
和19
我试图做\((\d+)\)*
但这只是给了我12
,25
,14
,19
任何帮助表示赞赏。
您可以将正向前瞻性与负向前瞻性结合使用,以获得所需的结果。
(\d+)(?=(?:.(?!\())*\))
正则表达式:
( group and capture to \1:
\d+ digits (0-9) (1 or more times)
) end of \1
(?= look ahead to see if there is:
(?: group, but do not capture (0 or more times)
. any character except \n
(?! look ahead to see if there is not:
\( '('
) end of look-ahead
)* end of grouping
\) ')'
) end of look-ahead
观看演示
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句