How to write Python regular expression to match with file extension?


The following code using regex matches the file extension in the given file name.

Example

import re
result = re.search('.doc$', '87654_3.doc')
print result.group()

Output

This gives the output

.doc

Updated on: 20-Feb-2020

584 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements