RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Parse & Extract Filename Parts
Expression
^(.*?)([^/\\]*?)(\.[^/\\.]*)?$
Description
Simple (non-validating) match with numbered group captures that extracts parts of a filename into $1 = folder path, $2 = filename w/o extension, $3 = extension. Should work on Windows, OS X, and Unix/Linux, but not on OS 9 and OSs with folder separators other than slashes (either direction). Tested only on .NET RE engine.
Matches
test | test.txt | C:\test | C:\test.txt | C:\test.txt\testing.txt | C:\folder\test | C:\folder\test.txt.txt | C:\folder\test.txt.txt\testing.txt | /usr/test | /usr/test.txt | /usr/test.txt/testing.pdf
Non-Matches
N/A (some captures may end up being blank in the event of a relative path or no file extension)
Author Rating: The rating for this expression. Matthew
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials