Skip to content

Instantly share code, notes, and snippets.

@MaxBarraclough
Last active May 19, 2017 17:10
Show Gist options
  • Save MaxBarraclough/b4878daf17b6fbae91ffcc8e483fb184 to your computer and use it in GitHub Desktop.
Save MaxBarraclough/b4878daf17b6fbae91ffcc8e483fb184 to your computer and use it in GitHub Desktop.
Unexpected different behaviour when using parentheses in C# regex
System.Text.RegularExpressions.Regex separatorRegex1
= new System.Text.RegularExpressions.Regex("a");
System.Text.RegularExpressions.Regex separatorRegex2
= new System.Text.RegularExpressions.Regex("(a)");
string str = "a";
string[] split1 = separatorRegex1.Split(str); // { "", "" }
string[] split2 = separatorRegex2.Split(str); // { "", "a", "" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment