Try this code it will help you: (^[A-Z][a-z]{2,}_[A-Z][a-z]{2,})
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(^[A-Z][a-z]{2,}_[A-Z][a-z]{2,})";
string input = @"Firstname_Lastname
fi_na
Fi_na
fi_Na
Fir_Name
Firs_name
firs_Name";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Here is the demo: https://regex101.com/r/8RUcaG/1
1
solved C# Regex for Username