1

I want to construct a regular expression which is of the format "xxxxx-xxxxxxx-x" where x are all numbers...Help?

EDIT:

I have this so far:

string pattern = @"\d{5}[-]"
faizanjehangir
  • 2,771
  • 6
  • 45
  • 83

3 Answers3

2

that regex would look like this:

string pattern = @"\b\d{5}-\d{7}-\d";

also checkout this tutorial

http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial

2pietjuh2
  • 879
  • 2
  • 13
  • 29
2
Regex.Match(input, @"\b\d{5}-\d{7}-\d$");
Dmitrii Dovgopolyi
  • 6,231
  • 2
  • 27
  • 44
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
  }
}
David Brabant
  • 41,623
  • 16
  • 83
  • 111