I have the following code:
var regex = new Regex(@"^\d+\b");
Console.WriteLine(regex.IsMatch("x 10", 2)); // False
Console.WriteLine(regex.IsMatch("x 10".Substring(2))); // True
Is there a character to use in my pattern besides ^ that will let me specify a startat parameter and still yield the same results as taking the equivalent substring? In other words, can I match the beginning of the substring I’m testing, even if it’s not necessarily the beginning of the string I’m passing in? I will be moving the regex along the string, so I don’t want to create a ton of substrings and I can’t hardcode it into my pattern.
Try
\G, eg:\Gmatches at the point where the previous match ended (or start of string of not matched before).