using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\b[0-9]{10}\b";
string input = @"National Provider Identifier
Requirements: 10 consecutive digit number
Pattern:
\b[0-9]{10}\b
Test Cases:
Positive (should fire):
10 digits consecutively 1234507890
Embedded in text with spaces NPI: oops 1234507890 there is text here
Negative (should not fire):
Too many digits 12345078901
Not consecutive 1234567-890
Embedded in text no spaces oops1234507890there is text here
Phone number formats:
2028080012 (this one will fire, false positive)
202-808-0012
202.808.0012
202 808 0012 ";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx