1

Goal:
The first letter shall be a small or a big character only and after that, the data ":\\" is should follow along. Data ":\\" is static.

Problem:
I have problem with my regex code.

^[a-zA-Z]:*$

Info:

C:\\dd\\sd\\faf.txt      true
c:\\ss\\dw\\fbf.txt      true
D:\\ff\\d3\\fcf.txt      true
d:\\da\\ds\\Df\\ff.txt   true
2:\\ad\\dd\\ff           false
2:\ad\\dd\\ff            false
d:\da\\ds\\Df\\ff.txt    false
c\\ss\\dw\\fbf.txt       false
D:\da\\ds\\Df\\ff.txt    false
HelloWorld1
  • 13,688
  • 28
  • 82
  • 145
  • Do your strings really contain double backslashes, or is that just how they look in your string literals? Are you aware that you can use C# *verbatim string* literals to avoid all that double-backslash hassle? For example, `var myString = @"C:\dd\sd\faf.txt";` creates the exact string `C:\dd\sd\faf.txt` – Alan Moore Dec 29 '15 at 02:03
  • I'm aware about it. Due to syntax code HttpPostedFileBase from asp.net mvc you retrieve it. – HelloWorld1 Dec 29 '15 at 06:52

3 Answers3

1

You need to detect correct PATH format in Windows.
Using this pattern can help: ^[a-zA-Z]:(\\\\[^\\]+)*
You can check my sample. Also note I add one more test to it:

D:\\da\\ds\Df\\ff.txt    false
Ali Nikneshan
  • 3,500
  • 27
  • 39
0

Close your missing a .* after the : Below should work.

^[a-zA-Z]:.*$ 
inic
  • 522
  • 4
  • 10
0

Look what Expresso can do for you:

enter image description here

Steve Wellens
  • 20,506
  • 2
  • 28
  • 69