当前位置:编程学习 > C#/ASP.NET >>

求一正则表达式

我有一字串需要拆分,如下:
 "a"&"b"&"c"||"d" 或
 "a" & "b" &   "c"  ||   "d"
 
希望可以拆分为四个子字串:
 a
 b
 c
 d 


如果是下面的字串:
 "a & "b" & "c"||"d"
 我想做到拆分出来的字串为:
 a&"b
 c
 d
  正则表达式 --------------------编程问答-------------------- 帮帮忙,各位高手 --------------------编程问答--------------------
void Main()
{
Regex reg=new  Regex(@"""\s*(?:&|\|\|)\s*""?|""$|^""");
string[] test=new string[]{"\"a\"&\"b\"&\"c\"||\"d\"",
"\"a\" & \"b\" &   \"c\"  ||   \"d\"",
"\"a & \"b\" & \"c\"||\"d\""};
foreach(string s in test)
{
   string[] result=reg.Split(s);
   foreach(string r in result)
     Console.Write(r+"\t");
   Console.WriteLine();
}
}


	a	b	c	d		
a b c d
a & "b c d
--------------------编程问答-------------------- 我这里有个笨办法你可以试试(?<>.*)/"?/"
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,