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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^((?:[a-zA-Z]:)|(?:\\{2}\w[-\w]*)\$?)\\(?!\.)((?:(?![\\/:*?<>"|])(?![.\x20](?:\\|$))[\x20-\x7E])+\\(?!\.))*((?:(?:(?![\\/:*?<>"|])(?![ .]$)[\x20-\x7E])+)\.((?:(?![\\/:*?<>"|])(?![ .]$)[\x20-\x7E]){2,15}))?$
Description
Matches drives, folders and file on a Windows OS. Folder matches must end with \ Folder and file names can not end with a space. I limited the file extension length to 15 though that not a restriction of a file's extension This is a mod of Darren's regex http://www.regexlib.com/REDetails.aspx?regexp_id=357 and my own http://www.regexlib.com/REDetails.aspx?regexp_id=137 Updated Feb 2005
Matches
C:\ | \\Server\share\path\File.txt | E:\My Files\Are\#1\
Non-Matches
C: | C:\\\ | C:\Trailing Space \
Author Rating: Not yet rated. Michael Ash
Source Michael Ash
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

Title: Relitive Paths
Name: Adam
Date: 4/22/2009 12:13:54 PM
Comment:
it dosen't match relitive paths. .\folder\file.ext ..\folder\file.ext ..\..\folder\file.ext Can you add this, or point me to a regexp which dose it?


Title: Matches invalid UNC
Name: Coward
Date: 5/8/2008 12:59:57 PM
Comment:
It matches the following which is an invalue UNC path \\Server\


Title: Not .NET Compatible
Name: AD
Date: 2/14/2006 11:16:43 AM
Comment:
Does not match anything past C:\ in .NET


Title: Re: Questio
Name: Michael Ash
Date: 8/26/2005 5:05:53 PM
Comment:
Most likely there is a character in the regex that needs to be escaped for Perl. My first guess would be the double quotes (") in the pattern but I don't know Perl. Try replacing every " with \x22


Title: Questio
Name: JR
Date: 8/26/2005 11:53:21 AM
Comment:
I am trying to use your RE in Perl but get this error: Unmatched ) before HERE mark in regex m/((?:[a-zA-Z]:)|(?:\{2}\w[-\w]*)\$?)\(?!\.) << HERE (((?:(?![\/:*?<>"|])(?![.\x20](?:\|$))[\x20-\x7E])+\(?!\.))*((?:(?:(?![\/:*?<>"|])(?![ .]$)[\x20-\x7E])+)\.((?:(?![\/:*?<>"|])(?![ .]$)[\x20-\x7E]){2,15}))?/ at B:\perlTest\testv1.6.pl line 137. It was entered as is.


Title: Sever name as IP address
Name: Tony Gray
Date: 7/7/2005 10:09:19 PM
Comment:
Does not handle server names with IP addresses in UNC. eg. \\192.168.0.1\folder\file.ext Also does not handle server names with periods eg. \\server.syd.1\folder\file.ext


Title: Re: Last two comments
Name: Michael Ash
Date: 2/1/2005 10:54:27 AM
Comment:
The regex has been updated to accommodate the statements in the two previous comments. Also the captures were changed to get 1) Drive 2) Last folder (Or all folders for .net captures) 3) File name (with ext) 4) Extension


Title: dashes in UNC
Name: Alastair Vance
Date: 2/1/2005 7:51:21 AM
Comment:
It doesn't like dashes in a UNC path. E.g. \\ni-cr-cts-3926cHow would I add that?


Title: forgotten? point not allowed at begining or end..
Name: Luis Carranza
Date: 1/29/2005 7:21:18 PM
Comment:
on files (before extension) and folders in windows. c:\datadir\.subdirc:\.datadir


Title: Help for validation
Name: Junior
Date: 11/12/2004 9:24:27 AM
Comment:
I need to validate the next string: C:\examploe\99990000000033h101004478.moc I validate the .moc extension, but how do i validate the that file is a integer of 23 positons ^((?:[a-zA-Z]:)|(?:\\{2}\w+)\$?)\\(?:(?:(?![\\/:*?<>"|])(?!\x20(?:\\|$))[\x20-\x7E])+\\)*((?:((?![\\/:*?<>"|])(?![ .]$)[\x20-\x7E])+)\.(?:((?![\\/:*?<>"|])(?![ .]$)[\x20-\.moc]){3}))?$


Title: Javascript
Name: C Johnson
Date: 10/28/2004 10:23:01 AM
Comment:
Is there a working version of this regex in javascript? Can you post it here?


Title: Re: Syntax Error in client side script
Name: Michael Ash
Date: 10/20/2004 1:38:02 PM
Comment:
For client side use replace ?> with ?: Client-side engines don't support the ?> syntax


Title: Syntax Error in client side script
Name: Leny Paul
Date: 9/30/2004 1:07:20 AM
Comment:
This Reg expression causes Syntax Error in client side script (both Java script and vb script). Too long one ! Modified RegExp http://regexlib.com/REDetails.aspx?regexp_id=137 will do the same. ^(([a-zA-Z]:)|(\\{2}\w+))(\\(\w[\w .]*\w))*(\\)$ Except for "C:\Trailing Space \"


Title: Changed from
Name: Michael Ash
Date: 8/18/2004 5:03:04 PM
Comment:
^((?:[a-zA-Z]:)|(?:\\{2}\w+)\$?)\\([^\\/:*?<>"| ](?:[^\\/:*?<>"|]*[^\\/:*?<>"| ])*\\)*((?:[^\\/:*?<>"|]*[^\\/:*?<>"| ])+\.(?:[^\\/:*?<>"|]*[^\\/:*?<>"| ]){2,15})?$ was the previous version


Title: Update
Name: Michael Ash
Date: 8/18/2004 5:00:33 PM
Comment:
Changed from ^((?:[a-zA-Z]:)|(?:\\{2}\w+)\$?)\\(?>(?>(?![\\/:*?<>"|])(?!\x20(?:\\|$))[\x20-\x7E])+\\)*((?:((?![\\/:*?<>"|])(?![ .]$)[\x20-\x7E])+)\.(?:((?![\\/:*?<>"|])(?![ .]$)[\x20-\x7E]){2,15}))?$ which Darren pointed out could run long in some cases, to the current version. The update version is limited to the ASCII character set for allowable characters.


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