python 用正则表达式 把一行中指定位置的字符取出来

把 from obps.a_b_1 ab where ab.conprition = '#conprition#' 这一行中的别名ab取出来,特点是取得值是在obps.表名 的后面(注意表名和别名中间有空格)

import re

_str = "from obps.a_b_1 ab where ab.conprition = '#conprition#'"

_str = re.sub(r'[\w]* obps.[\w]* ', "", _str)
_str = re.sub(r' where [\w. \'# =]*', "", _str)

print(_str)