Ben
Ben

Reputation: 4319

Regex split with semi-colon gives unexpected results

I am trying to split a string, in the following format:

9A ##{Indie; Rock}##

(The string comes from an mp3 tag via TagLib)

The code is:

        string[] parts = Regex.Split(comment,"##{");
        string prefix = parts[0];
        Console.WriteLine(parts[1]);
        string[] parts2 = Regex.Split(parts[1], "}##");
        string keywords = parts2[0];
        string suffix = parts2[1];

However, at the console.writeline, I'm getting back:

Indie

Whereas I'd expect:

Indie; Rock}##

I assume it's something today with the semi-colon terminating the line early, but I don't know why (or how to fix it).

Upvotes: 0

Views: 188

Answers (1)

Jras
Jras

Reputation: 518

Try using capture groups. http://www.regular-expressions.info/named.html

This regex worked for me

##{(?<first>.*);(?<second>.*)}##

Also, Expresso can be very useful for regex problems http://www.ultrapico.com/ExpressoDownload.htm

Upvotes: 2

Related Questions