Why regular experssion'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 2:53 UTC
Read the original article Hit count: 260

Filed under:
|

as 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

Related posts about python

Related posts about regex