pythonregex

Regex for string ending with particular pattern


Hel lo, I just need the command in regex to ask to find any string that end with a . and any number

for instance

ASGSGSGGS.2
AHHAHAHAH.4
DJDDKGDGD.4

thank you for your help

I tried :

re.match(r".\.[0-9]",i)

Solution

  • You can just use the $ anchor to match the end of the string:

    re.search(r"\.[0-9]$", i)
    

    Also, note that I'm using re.search instead of re.match. You can read about the differences between both functions here.