我想构建一个格式为“xxxxx-xxxxxxx-x”的正则表达式,其中x都是数字......帮助?
编辑:
到目前为止,我有这个:
string pattern = @"\d{5}[-]"
答案 0 :(得分:2)
正则表达式看起来像这样:
string pattern = @"\b\d{5}-\d{7}-\d";
也请查看本教程
http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial
答案 1 :(得分:2)
Regex.Match(input, @"\b\d{5}-\d{7}-\d$");
答案 2 :(得分:1)
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
}
}