I need a regular express for :
letter number letter number letter number format.
eg : "E7R8R9".
Below is my code:
string txt = "G1R1A3";
// Any Single Word Character (Not Whitespace) 1
string re1 = "[a-z][0-9][a-z][0-9][a-z][0-9]";
Regex r = new Regex(re1, RegexOptions.IgnoreCase | RegexOptions.Singleline);
Match m = r.Match(txt);
if (m.Success)
{
String w1 = m.Groups[1].ToString();
Console.Write("(" + w1.ToString() + ")" + "\n");
}
Console.ReadLine();
But this code matches "GG1R1A3" this also.
Please help.
Your code is searching for the pattern anywhere within your string. If you want to anchor it to the start (and end) of the string, use
^and$: