其他教程

其他教程

Products

当前位置:首页 > 其他教程 >

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

GG网络技术分享 2025-03-18 16:14 11


问题描述:

把 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)

python中的字符串和正则表达式全解

一、转义字符

正则表达式是建立在字符串的基础上,当需要在字符中使用特殊字符时,python用反斜杠\\转义字符。

如下表:

标签:

提交需求或反馈

Demand feedback