例如:
import re pattern = r"(?P<first>abc)(?:def)(ghi)" match = re.match(pattern, "abcdefghi") if match: print(match.group("first")) print(match.groups())
结果:
>>> abc ('abc', 'ghi') >>>
0