【发布时间】:2019-07-10 18:41:58
【问题描述】:
我正在尝试使用正则表达式来查看字符串的特定部分并获取介于两者之间的内容,但我无法为此获得正确的正则表达式模式。
我最大的问题是试图为此形成一个正则表达式模式。我已经尝试了一系列接近所列示例的变体。它应该很接近。
import re
toFind = ['[]', '[x]']
text = "| Completed?|\n|------|:---------:|\n|Link Created | [] |\n|Research Done | [X] "
# Regex to search between parameters and make result lowercase if there are any uppercase Chars
result = (re.search("(?<=Link Created)(.+?)(?=Research Done)", text).lower())
# Gets rid of whitespace in case they move the []/[x] around
result = result.replace(" ", "")
if any(x in result for x in toFind):
print("Exists")
else:
print("Doesn't Exist")
快乐之路: 我采用字符串(文本)并使用正则表达式来获取 Link Created 和 Research Done 之间的子字符串。
然后将结果设为小写并去掉空格,以防他们移动 []/[x]。然后它查看 '[]' 或 '[x]' 的字符串(结果)并打印。
实际输出: 目前我得到的只是无,因为正则表达式语法已关闭......
【问题讨论】:
标签: python regex python-3.x