MediSoft
MediSoft

Reputation: 161

Split with regular expression

How can i split string with char that is not part of the in parenthesis string

Exemple :

"(ab);(cd)" split with (;) ==> (ab) and (cd)

"(ab;cd);(abcd)" split with (;) ==> (ab;cd) and (abcd)

I can't find the regular expression solution for this thank you for your help

Upvotes: 2

Views: 88

Answers (2)

w.b
w.b

Reputation: 11228

@"(?<=\));(?=\()" also works:

string str = "(ab;cd);(abcd)";

string[] arr = Regex.Split(str, @"(?<=\));(?=\()");

foreach (string str in arr)
    Console.WriteLine(str); 

// (ab;cd)
// (abcd)

Upvotes: 1

codekaizen
codekaizen

Reputation: 27429

Try:

Regex.Split(s, @"(;(?!(\w*\))))")

Upvotes: 2

Related Questions