Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression Split?

Status
Not open for further replies.

vladibo

Programmer
Sep 14, 2003
161
CA
How to write regular expression that Splits by ',' but not by '\,'

so if I have

string str = @"Aa aa\,\,aa aaA,\,,Bbbb bbb bbB";
string pattern = ?

string[] strArr = Regex.Split(str,pattern);
Console.WriteLine("# Elements: "+strArr.Length);
for(int i=0;i<strArr.Length;i++){
Console.WriteLine(i+"|"+strArr+"|");
}

The result should be:

0|Aa aa\,\,aa aaA|
1|\,|
2|Bbbb bbb bbB|

But what is the pattern?

Thanks

 
something like ".*?," ?

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Not a clue, here is a hack.
Code:
string sPattern = ",";
string str = @"Aa aa\,\,aa aaA,\,,Bbbb bbb bbB";
str = str.Replace(@"\,","&^&");
Regex regex = new Regex(sPattern); 
string[] strArr = regex.Split(str);
string str1;
for(int i=0;i<strArr.Length;i++){
	str1 = strArr[i].Replace("&^&",@"\,");
	Console.WriteLine(i+"|"+str1+"|");
}
Marty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top