In the snippet below, the non-capturing group "(?:aaa)" should be ignored in the matching result,
The result should be "_bbb" only.
However, I get "aaa_bbb" in the matching result; only when I specify group(2) does it show "_bbb".
>>> import re
>>> s = "aaa_bbb"
>>> print(re.match(r"(?:aaa)(_bbb)", s).group())
aaa_bbb
group()andgroup(0)will return the entire match. Subsequent groups are actual capture groups.If you want the same behavior than
group():" ".join(re.match(r"(?:aaa)(_bbb)", string1).groups())