import re a = 'from obps.a_2b2 obps.a_c3 obps.a_d4' a1 = re.compile(r'obps.+\w') b = a1.findall(a,re.IGNORECASE) print b
输出:['obps.a_2b2 obps.a_c3 obps.a_d4']
如何只输出obps字符后面的字符,a_2b2,a_c3,a_d4
import re a = 'from obps.a_2b2 obps.a_c3 obps.a_d4' a1 = re.compile(r'obps.+\w') b = a1.findall(a,re.IGNORECASE) print b
输出:['obps.a_2b2 obps.a_c3 obps.a_d4']
如何只输出obps字符后面的字符,a_2b2,a_c3,a_d4
收起
可以这样写
r"(?<=obps\.).*?(?=\s|$)"
报告相同问题?