正则表达式Python分组覆盖

2024-04-20 03:16:50 发布

您现在位置:Python中文网/ 问答频道 /正文

字符串是'POSIX TAR ARCHIVE(GNU)' 正则表达式模式'(TAR)|(POSIX)'

python代码:

import re 
pattern = '(TAR)|(POSIX)'
string = 'POSIX TAR ARCHIVE (GNU)'
match = re.search(pattern, string , re.IGNORECASE)
match.groups()

结果只是POSIX而不是tar 为什么?你知道吗


Tags: 字符串代码gnuimportresearchstringmatch