我想构造一个格式为“xxxxx-xxxxxxx-x”的正则表达式,其中 x 都是数字...帮助?
编辑:
到目前为止我有这个:
string pattern = @"\d{5}[-]"
该正则表达式看起来像这样:
string pattern = @"\b\d{5}-\d{7}-\d";
还可以查看本教程
http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial
Regex.Match(input, @"\b\d{5}-\d{7}-\d$");
string strRegex = @"[0-9]{5}\-[0-9]{7}\-[0-9]{1}";
RegexOptions myRegexOptions = RegexOptions.None;
Regex myRegex = new Regex(strRegex, myRegexOptions);
string strTargetString = @"12345-1234567-9";
foreach (Match myMatch in myRegex.Matches(strTargetString))
{
if (myMatch.Success)
{
// Add your code here
}
}