I would like to use the regex pattern ((?!(SEPARATOR)).)*to split the string.
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
var separator = "__";
var pattern = String.Format("((?!{0}).)*", separator);
var regex = new Regex(pattern);
foreach (var item in regex.Matches("first__second"))
Console.WriteLine(item);
}
}
It works great when it SEPARATORis the only character, but when it is longer than 1 character, I get an unexpected result. In the above code, the second line matches "_second" instead of "second". How can I change my template to skip the whole unique separator?
My real problem is line splitting where I have to skip line separators inside quotes. My line separator is not a predefined value and may be, for example, "\ r \ n".