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
  • 732,580
  • 175
  • 1,330
  • 1,459
Abubakar
  • 97
  • 8

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,241
  • 9
  • 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
  • 607,720
  • 39
  • 448
  • 563