Regex for extracting filename from path

^\\(.+\\)*(.+)\.(.+)$

This regex has been tested on these two examples:

\var\www\www.example.com\index.php
\index.php

First block “(.+\)*” matches directory path.
Second block “(.+)” matches file name without extension.
Third block “(.+)$” matches extension.

Leave a Comment