0

I have a list of paths with files name. The file's name can be random.

I tried using re module with regex tested using online tools. But it return none. Using pathlib.Path.match return what I wanted.

l = ["C:/dir/1.png", "C:/dir/a2.png", "C:/dir/2a.png", "C:/dir/a.txt", "C:/dir/x4-444.exe"]
    
pat = re.compile(r"\.png$")

for p in l:
    print("re" ,re.match(pat, p)) # none none none none none
    print("Path", pathlib.Path(p).match("*.png")) # true true true false false

I read that re.match() only return what it found at the start of the string, which isn't the case here. How can I use re module in this case? Or should I just stick with Path.match?

AdvMaple
  • 99
  • 1
  • 7

0 Answers0