0

I want to create a regex to match one or two digits, followed by the character "M", followed by two digits, and then matching anything else, but it doesn't quite work:

I have this regex pattern:

string astring = "3M90-75";
string sPattern = "^\\d{1}M\\d{2}}$";
if (System.Text.RegularExpressions.Regex.IsMatch(astring, sPattern))
{
     //It's a match.
}
Ivan
  • 7,448
  • 14
  • 69
  • 134

1 Answers1

0

Use ^\d{1,2}M\d{2}.*:

  • \d{1,2}M One or two digit before M
  • \d{2} Two digit after M
  • .* To include the rest of string