Why regular expression's "non-capturing" group is not working
Posted
by Jim Horng
on Stack Overflow
See other posts from Stack Overflow
or by Jim Horng
Published on 2010-04-24T02:48:14Z
Indexed on
2010/04/24
3:03 UTC
Read the original article
Hit count: 267
In my snippet below, the non-capturing group "(?:aaa)"
should be ignored in matching result,
so the result should be "_bbb"
only.
However, I get "aaa_bbb"
in matching result; only when I specify group(2) does it show "_bbb"
.
import re
string1 = "aaa_bbb"
print(re.match(r"(?:aaa)(_bbb)", string1).group())
>>> aaa_bbb
© Stack Overflow or respective owner