PythonRegex捕获组,其中包含嵌套的非捕捉组

问题描述 投票:0回答:1
Abb

Ab
A
C###
C#
C
等。
b
#
)进入一个单独的组。 我正在使用此正则:
sample = "Cbb-7" # for testing purposes
re.search(r"([A-G](?:#*|b*))(.*?)", sample).groups()
therepresults
在:

('C', '')
当我期待:
('Cbb', '-7')

. 将正则ggex修改为(贪婪的后续捕获组

(.*)
)时:
re.search(r"([A-G](?:#*|b*))(.*)", sample).groups()

我得到

result

('C', 'bb-7')
。 (我仍然需要:
('Cbb','-7')

移动the的选择性,非捕捉组的the Out似乎有所帮助:
b

results
python regex python-re
1个回答
0
投票

#
仍然想知道为什么!
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.