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
  • 675,133
  • 158
  • 1,253
  • 1,388
Abubakar
  • 19
  • 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,128
  • 7
  • 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
  • 484,719
  • 26
  • 302
  • 397