import re
s="jsldjflsjflkj_name_kjddskjfk_from_1" pattern = re.compile('_name_(.*)_from_') result = pattern.findall(s) print result
输出结果为:kjddskjfk
import re
s="jsldjflsjflkj_name_kjddskjfk_from_1" pattern = re.compile('_name_(.*)_from_') result = pattern.findall(s) print result
输出结果为:kjddskjfk