Reputation: 1211
let's say i have this line string:
'''Sir Winston Leonard Spencer-Churchill''', {{Post-nominals|post-noms=[[Knight of the Garter|KG]]
i already got to use string split with no empty results in my code, but i want now the result for that string will be:
[0] "'''" [1] "Sir Winston Leonard Spencer-Churchill" [2] "'''" [3] ", " [4] "{{" [5] "Post-nominals|post-noms=" [6] "[[" [7] "Knight of the Garter|KG" [8] "]]"
and so on, so basicaly my delimeters are {"'''","{{","}}","[[","]]"}
just need the way for it, i'll edit that later. if it won't be with regex it'll be better.
Upvotes: 0
Views: 248
Reputation: 9214
Using Regex
:
string input = "'''Sir Winston Leonard Spencer-Churchill''', {{Post-nominals|post-noms=[[Knight of the Garter|KG]]";
string pattern = @"('''|\{\{|\}\}|\[\[|\]\])";
string[] result = Regex.Split(input, pattern);
Upvotes: 3
Reputation: 13450
use this regex (?<=^?'''|\{\{|\[\[|\]\]|\}\})(.+?)(?=$?'''|\{\{|\[\[|\]\]|\}\})
Upvotes: 0