Archive for April 6th, 2009
Regex that matches path, filename and extension
I was looking for a regular expression for Python capable to match a string containing a valid path, filename and extension. Finally, I discovered following solution:
^(.*/)?(?:$|(.+?)(?:(\.[^.]*$)|$))
Let me explain how I got this regular expression. Fortunately, Scott Carpenter has written an excellent article about a regular expression to match a filename with extension. Matching the filename extension is not trivial for all possible situations.
Add comment April 6, 2009