C# string starts with a number regex

Your regex is wrong. /.../ is javascript convention for defining regular expressions. Try like this in C#:

if (Regex.IsMatch(info, @"^\d"))

Also notice that you should use the IsMatch method which returns boolean or your code won't even compile.

And if you wanted to match that the string starts with one or more digits:

if (Regex.IsMatch(info, @"^\d+"))

You don't need a regex for this. Try

if (info.Length > 0 && char.IsDigit(info[0]))
{
   ...
}

If you want to use the regex, take out the // so it's just Regex.IsMatch(info,@"^\d").


It's the format of the string that you've supplied to Regex.Match.

The correct format would be:

Regex.Match(info,@"^\d")

The @ means that escape characters (like the backward slash) are treated as normal characters. Without it your regex would need to be "^\\d".