2024-09-23 22:21:07 发布
网友
x = re.findall(r'FROM\s(.*?\s)(WHERE|INNER|OUTER|JOIN|GROUP,data,re.DOTALL)
我使用上面的表达式来解析oraclesql查询并得到结果。 我得到多个匹配,并想打印他们每一行。 我怎么能那样做。 有些结果甚至介于两者之间
结果将以列表形式返回。 从https://docs.python.org/2/library/re.html:
re.findall(pattern, string, flags=0) Return all non-overlapping matches of pattern in string, as a list of strings.
如果您不熟悉数据结构,更多信息here 您应该能够使用for循环轻松地遍历返回的列表:
for matchedString in x: #replace commas n = matchedString.replace(',','') #to replace commas #add to new list or print, do something, any other logic print n
你可以试试这个:
for elt in x: print('\n'.join(elt.split(',')))
join返回逗号分隔元素的列表,然后这些元素再次与\n(新行)连接。因此,每行得到一个结果
join
\n
结果将以列表形式返回。 从https://docs.python.org/2/library/re.html:
如果您不熟悉数据结构,更多信息here 您应该能够使用for循环轻松地遍历返回的列表:
你可以试试这个:
join
返回逗号分隔元素的列表,然后这些元素再次与\n
(新行)连接。因此,每行得到一个结果相关问题 更多 >
编程相关推荐