【发布时间】:2017-03-22 06:56:03
【问题描述】:
我想检查它是驱动器路径还是“pol”路径。 为此我已经写了一个小代码,不幸的是,我总是返回 true。
正则表达式可能不正确\W?\w{1}:{1}[/]{1}。我该怎么做才对?路径名称总是可以不同的,不必与极路径一致。
提前谢谢你。
public bool isPolPath(string path)
{
bool isPolPath= true;
// Pol-Path: /Buy/Toy/Special/Clue
// drive-Path: Q:\Buy/Special/Clue
Regex myRegex = new Regex(@"\W?\w{1}:{1}[/]{1}", RegexOptions.IgnoreCase);
Match matchSuccess = myRegex.Match(path);
if (matchSuccess.Success)
isPolPath= false;
return isPolPath;
}
【问题讨论】:
-
区分 pol 或驱动路径的规则是什么?对于给定的输入示例:
return path.StartsWith("/"); -
为了让问题更清楚,请同时提供一组测试用例