Have the problem with regexp on C#. I get the list of strings (names of directory) by Directory.GetDirectories. For example:
E:\DevArea\SandBox\1122334455
E:\DevArea\SandBox\1231231231
E:\DevArea\SandBox\1231231232
E:\DevArea\SandBox\1231231233
E:\DevArea\SandBox\1231231234
E:\DevArea\SandBox\123123123123
E:\DevArea\SandBox\1231231231ddd
I need to find directories names witch consists of only 10 digits (only 10). I tried to use next:
public List<string> GetDirectoryList()
{
var directoryList = new List<string>();
var list = Directory.GetDirectories(sourcePath);
foreach (var field in list)
{
if (checker.CheckInfo(field.Substring(field.LastIndexOf('\\') + 1)))
{
directoryList.Add(field);
}
}
return directoryList;
}
public bool CheckInfo(string checkingInfo)
{
string stringPattern = "[0-9]{10}";
if (!Regex.IsMatch(checkingInfo, stringPattern))
{
return false;
}
return true;
}
As result i had list of directories names witch consist of digits, but there were the next one:
E:\DevArea\SandBox\123123123123
How can i ignore names with more than 10 digit?
(?<!\d)[0-9]{10}(?!\d)^\d{10}$