-1

Can some body help me, I'm new to c#, I know this question has been asked several times before. The code below is supposed to be looking for specific directories but it doesn't seem to match the regex. I have tested the expression on regex101.com and it worked fine.

matching string should return True: \TestData\FXLH_TestData

matching string should return False: \TestData\FXLH_TestData_manifest

string dirReg = "([A-Z]+_TestData)[^_manifest]";

foreach (string subDir in Directory.GetDirectories(target))
{

  if (Regex.IsMatch(subDir, dirReg)

       Console.WriteLine("success");

  else

       Console.WriteLine("fail");                       
}
ctwheels
  • 21,901
  • 9
  • 42
  • 77
Cagbuya
  • 1
  • 2

1 Answers1

-1

if you are looking for the files that end in _TestData, you can use this code

string dirReg = "_TestData$";

foreach (string subDir in Directory.GetDirectories(target))
{
  if (Regex.IsMatch(subDir, dirReg))
       Console.WriteLine("success");
  else
       Console.WriteLine("fail");                       
}
Mapaxe
  • 1
  • 1
  • 2
  • 1
    Why even use regex then? Just use [EndsWith](https://msdn.microsoft.com/en-us/library/system.string.endswith(v=vs.110).aspx) – ctwheels Mar 29 '18 at 17:17
  • Exactly my thought, I don't think there is a requirement for regex here. – Kevin Mar 29 '18 at 17:18