if(Regex.IsMatch("thisIsaString-A21", "-A\\d+")) {
If you really want to extract the -A [num] bit, you can do this:
var m = Regex.Match("thisIsaString-A21", "-A\\d+")); if(m.Success) { Console.WriteLine(m.Groups[0].Value);
There are other things you can do — for example, if you need to extract the A [num] bit yourself or just a number:
var m = Regex.Match("thisIsaString-A21", "(?<=-A)\\d+");
Or, as in my first sentence, if you want "A21":
var m = Regex.Match("thisIsaString-A21", "(?<=-)A\\d+");
There are other ways to achieve these last two — I like a non-capture group (?<=) , Because, as the name suggests, it retains pure output groups.
source share