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')
(.*)
)时:re.search(r"([A-G](?:#*|b*))(.*)", sample).groups()
我得到
result:
('C', 'bb-7')
。 (我仍然需要:
('Cbb','-7')
移动the的选择性,非捕捉组的the Out似乎有所帮助:b
results#
仍然想知道为什么!