日期:2014-05-20  浏览次数:20892 次

分割字符串正则表达式
有这样类似的字符串 :abc and deandf and "hij and abc and def or dcd" or "abc"

用 and|or 进行分割,但""双引号之间的 and|or 不作为分割符
结果如下
abc
deandf 
"hij and abc and def or dcd" 
"abc"



------解决方案--------------------
try...

C# code
            string test = "abc and deandf and \"hij and abc and def or dcd\" or \"abc\"";
            Regex reg = new Regex(@"(?s)\b(?:and|or)\b(?=(?:(?:[^""]*""){2})*[^""]*$)");
            string[] result = reg.Split(test);
            foreach (string s in result)
            {
                richTextBox2.Text += s + "\n";
            }