Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用键模式提取子字符串值_Python - Fatal编程技术网

Python 使用键模式提取子字符串值

Python 使用键模式提取子字符串值,python,Python,可能是一个正则表达式问题(请原谅我的蹩脚英语) 我需要识别以某个值开头的子字符串 例如,以以下字符串为例: “从user.table1内部联接用户中选择1。table2…” 我需要提取所有以“user”开头,以“blankspace”结尾的单词。因此,将此“未知”正则表达式应用于上述字符串后,将产生以下结果: 表1 表2 我尝试使用“re.findall”函数,但找不到指定开始和结束模式的方法 那么,如何使用起始模式提取子字符串呢?您可以这样尝试: re.findall(r'\buser\.(.

可能是一个正则表达式问题(请原谅我的蹩脚英语)

我需要识别以某个值开头的子字符串

例如,以以下字符串为例:

“从user.table1内部联接用户中选择1。table2…”

我需要提取所有以“user”开头,以“blankspace”结尾的单词。因此,将此“未知”正则表达式应用于上述字符串后,将产生以下结果:

表1 表2

我尝试使用“re.findall”函数,但找不到指定开始和结束模式的方法


那么,如何使用起始模式提取子字符串呢?

您可以这样尝试:

re.findall(r'\buser\.(..*?)\b',
           "Select 1 from user.table1 inner join user.table2...")
这将返回:

['table1', 'table2']

您可以这样尝试:

re.findall(r'\buser\.(..*?)\b',
           "Select 1 from user.table1 inner join user.table2...")
这将返回:

['table1', 'table2']

尝试积极的回头看:

import re
pattern=r'(?<=user\.)(\w+)?\s'
string_1="Select 1 from user.table1 inner join user.table2 ..."

match=re.findall(pattern,string_1)
print(match)
正则表达式信息:


(?尝试正向查找:

import re
pattern=r'(?<=user\.)(\w+)?\s'
string_1="Select 1 from user.table1 inner join user.table2 ..."

match=re.findall(pattern,string_1)
print(match)
正则表达式信息:

(?
re.findall(r'\buser[^]*',txt)
[words.split(“.”[1]用于字符串中的单词。split(“”)if words.startswith(“user”)]
像这样尝试
re.findall(r'\buser[^]*',txt)
[words.split(“”[1]用于字符串中的单词。split if words.startswith(“user”)
像这样尝试