简体   繁体   中英

Python Regex, Matching Whole Words with Spaces with date and time

How would i match these specific lines from an XML file:

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

So far I currently match all strings

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

I am able to read the file just unable to extract these specific string from the file.

Since you haven't specified what you need to find, I can't give you a tested code snippet. Please check the various help pages and the regexp tutorials. I can recommend

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

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

I think that you may need something like this:

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

which easily collapses to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM