Python正则表达式,用带有日期和tim的空格匹配整个单词

2024-09-28 19:26:59 发布

您现在位置:Python中文网/ 问答频道 /正文

如何匹配XML文件中的这些特定行:

“<;Foobar>;示例创建于2014年9月30日上午11:00:010<;/Foobar>;AZ9999这是一个测试-请帮助备份完整”

到目前为止,我匹配所有字符串

    #Regex for matching specific line
   found = re.match(r"^(?<=FooBar)+(\d+/\d+/\d+).$", text)

我能够读取文件只是无法从文件中提取这些特定的字符串。你知道吗


Tags: 文件字符串ltgt示例forlinexml
1条回答
网友
1楼 · 发布于 2024-09-28 19:26:59

因为您还没有指定需要查找的内容,所以我无法提供经过测试的代码段。请查看各种帮助页和regexp教程。我可以推荐

http://flockhart.virtualave.net/RBIF0100/regexp.html

https://docs.python.org/2/howto/regex.html

我想你可能需要这样的东西:

def isText(text):
    found = re.match(r"This is a test", text)
    if found:
        return True
    return False

很容易塌下来

return re.match(r"This is a test", text)

相关问题 更多 >