Reputation: 65
Given a file path with folder name, file name and an optional file extension, I would like to capture the file name (without extension) and the extension.
For example:
"c:\temp\test.txt" -> matches = "test" and ".txt"
"c:\temp\blob" -> matches = "blob" and ""
Thanks in advance.
Upvotes: 1
Views: 1294
Reputation: 3959
This should match any characters, a backslash, any non-backslash and non-period characters (filename), and then an optional period and series of non-period/non-backslash characters for the extension.
^.*\\([^.\\]+)(\.[^.\\]+)?$
Upvotes: 2