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 it as an "else". In this case, it will work as if the regular expression were(?(x)bx|(?=b))
What's going on here? Is it intentional? This does not seem to be documented.
Edit: The problem was created in the corefx repository: https://github.com/dotnet/corefx/issues/26787
source
share