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}[-]"
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}[-]"
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
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
}
}