簡體   English   中英

Python Regex,將整個單詞與帶有日期和時間的空格匹配

[英]Python Regex, Matching Whole Words with Spaces with date and time

我將如何匹配 XML 文件中的這些特定行:

'< Foobar >example created 9/30/2014 11:00:010 AM</Foobar> AZ9999This Is A Test - Please Help Backup-Full'

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

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

我能夠讀取文件只是無法從文件中提取這些特定的字符串。

由於您尚未指定需要查找的內容,因此我無法為您提供經過測試的代碼片段。 請查看各種幫助頁面和正則表達式教程。 我可以推薦

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM