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.

(more…)

Add comment April 6, 2009


Disclaimer

This is the technical weblog of Daniel Felix Ferber. The postings on this site are his own and don’t necessarily represent neither IBM’s, Stefanini IT Solutions nor Petrobras positions, strategies or opinions.

My Personal Weblog

This weblog is dedicated for my technical articles written in English. If you are interested in my personal thoughs, or my articles in Portuguese, please visit Daniel Ferbers Weblog.

Blogroll

Feeds

Pages

 

April 2009
M T W T F S S
« Mar   Aug »
 12345
6789101112
13141516171819
20212223242526
27282930  

Archives

Meta