[Python] Python RegExp global flag

Discussão em 'Python' iniciado por Stack, Fevereiro 3, 2025.

  1. Stack

    Stack Membro Participativo

    Is there a flag or some special key in python to use pattern multiple times. I used to test http://gskinner.com/RegExr/ my RegExp, it worked correctly in it. But when testing in correct enviorment match only returns None.

    import re
    pattern = r"(?P<date>--\d\d-\w+:\d\d)[ \t]+(?P<user>\w+)[ \t]+(?P<method>[\w ]+)[\" ]* (?P<file>[\w\\:\.]+)@@(?P<version>[\w\\]+)[\" ]*(?P<labels>[\(\w, \.\)]+){0,1}[\s \"]*(?P<comment>[\w \.-]+){0,1}[\"]"
    base = """
    --02-21T11:22 user3 create version "W:\foo\bar\fooz.bat@@\main\1" (label1, label2, label3, label22, label33, ...)

    "merge in new bat-based fooz installer"

    --02-21T11:22 user1 create version "W:\foo\bar\fooz.bat@@\main\0"

    --02-21T11:22 user2 create branch "W:\foo\bar\fooz.bat@@\main\"

    "merge in new bat-based fooz installer"

    --02-13T11:22 user1 create version "W:\foo\bar\fooz.bat@@\main\1"

    "Made to use new fooz.bat"

    """
    r = re.match(pattern, base)
    print(r)

    Continue reading...

Compartilhe esta Página