Objective To find an exact match for a word that is exactly 7 characters, beginning with 3 letters followed by 4 digits within a sentence.
Valid Inputs: ABC1234, MOW0912, qbc1239
I have tried setting the length using
var result = Regex.Match(myString, "[A-Za-z]{3}[0-9]{4}\\d{9}");
I have referred couple of similar posts and didn't help me resolve the issue
C# Regular Expression Help Needed
Code: I have so far
using System;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
string[] data = { "This, is a test ,* P.O ABC12 and ABCDE5134 this is some random words UserID ABC1234 that the users may have, regards, and the end of it" };
foreach (string myString in data)
{
if (Regex.IsMatch(myString, "[A-Za-z]{3}[0-9]{4}"))
{
var result = Regex.Match(myString, "[A-Za-z]{3}[0-9]{4}");
Console.WriteLine("{0} matches", myString);
Console.WriteLine("result is" + result);
}
else
{
Console.WriteLine("does not match");
}
}
}
}
OUTPUT