我需要打印一次,因为我在python中使用正则表达式打印两次

时间:2017-09-20 05:29:44

标签: python python-3.x

importre
list = re.findall('SF:((/\w*)*.c$)','SF:/x/eng/rlse/DOT/devN_170820_0500/zephyr/src/libzapid/https_util.c')
print(list)

输出:

[('/x/eng/rlse/DOT/devN_170820_0500/zephyr/src/libzapid/https_util.c', '/https_util')]

但我只需要:

/x/eng/rlse/DOT/devN_170820_0500/zephyr/src/libzapid/https_util.c

1 个答案:

答案 0 :(得分:0)

在这种情况下,您可以使用搜索获取相应的组,而不是使用findall,如下所示

import re
list = re.search('SF:((/\w*)*.c$)','SF:/x/eng/rlse/DOT/devN_170820_0500/zephyr/src/libzapid/https_util.c')
print(list.group(1))