1
string strRegexclass = @"^([0-9]+)\-([a-zA-Z])$";

I want to make regular expression which accept input like this (1-class). Any integer value before dash(-) and then must have dash then anything after dash.

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Abubakar
  • 31
  • 7

2 Answers2

1

You can use the code like this:

string strRegexclass = @"^\d+-.*$";

Or you can use the next code

string strRegexclass = @"^\d+-\w*$";

if you want to allow only letters after the dash.

Ihor Dobrovolskyi
  • 1,191
  • 8
  • 19
0

If you plan to only match a string that starts with 1 or more ASCII digits, then a hyphen, and then any 0+ chars use:

^[0-9]+-.*$

See the regex demo

Note that \d and [0-9] are not equal in .NET regex flavor.

Community
  • 1
  • 1
Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476