Code:
Match match = Regex.Match("abc", "(?(x)bx)");
Console.WriteLine("Success: {0}", match.Success);
Console.WriteLine("Value: \"{0}\"", match.Value);
Console.WriteLine("Index: {0}", match.Index);
Output:
Success: True
Value: ""
Index: 1
It seems that a conditional group without an "else" expression will instead create a lookahead from the first character of the "if" expression and use that as the "else". In this case it would run as if the regex was (?(x)bx|(?=b))
What the **** is going on here? Is this intentional? It doesn't seem to be documented.
Edit: An issue has been created in the corefx repository: https://github.com/dotnet/corefx/issues/26787