So I have been trying to combine the answers of these two questions:
C# split string but keep split chars\seperators
Regex to match multiple strings
Essentially I'd like to be able to split a string around certain strings and have the splitting strings in the output array of Regex.Split()
as well. Here is what I have tried so far:
// ** I'd also like to have UNION ALL but not sure how to add that
private const string CompoundSelectRegEx = @"(?<=[\b(UNION|INTERSECT|EXCEPT)\b])";
string sql = "SELECT TOP 5 * FROM Persons UNION SELECT TOP 5 * FROM Persons INTERSECT SELECT TOP 5 * FROM Persons EXCEPT SELECT TOP 5 * FROM Persons";
string[] strings = Regex.Split(sql, CompoundSelectRegEx);
The problem is that it starts matching individual characters like E and U so I get an incorrect array of strings.
I'd also like to match around UNION ALL but since thats not just a single word but a string I wasn't sure how to add it the above regex so if someone could point me in the right direction there as well that would be great!
Thanks!