0

I am trying to use a reg ex which validates Windows path string. I am using the following reg ex

[\w]:\.* .

The following egs should be validated.

Abc.txt
HelloWorld\Abc.txt
..\Hello\World\Abc.txt
C:\Program Files\TaaSera\LiveTrust\Abc.txt

At present C:// is only getting validated. Please help.

6
  • : is metacharacter, it has to be escaped Commented Dec 9, 2015 at 9:01
  • @hindmost : do you mean something like this [\w]\.* Commented Dec 9, 2015 at 9:02
  • 1
    Maybe something like this? regexlib.com/REDetails.aspx?regexp_id=345 (there is alot more on that site) Commented Dec 9, 2015 at 9:03
  • @hindmost: Are you sure. While : forms part of various syntaxes (eg. not capturing groupd) it isn't a meta-character in its own right. Commented Dec 9, 2015 at 9:06
  • 2
    You seem to be looking for paths of the form "x:\name\…\name.ext. However there are also \\computer\share\…\name` and \\?\D:\very long path to bypass the normal file length limits. See MSDN for details. Commented Dec 9, 2015 at 9:13

1 Answer 1

1

Try with this regex:

^[\w\\.:\s]+?\.\w{2,4}

DEMO

Sign up to request clarification or add additional context in comments.

6 Comments

Abc.txt in this Abc$& is also getting accepted. I guess these special characters are not allowed in windows file name
@user2998990 ok, what about ^[\w\\.:\s]+?\.\w{2,4}?
Windows "normal" paths are driver letter, colon, backslash, and then names separated by backslashes.
@m.cekiera : seems ok... Thanks a ton. :)
@m.cekiera : C:// is not getting validated.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.