[英]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) (该字符串来自TagLib的mp3标签)
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: 但是,在console.writeline,我回来了:
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). 我认为今天早些时候使用分号终止该行,但我不知道为什么(或如何解决它)。
Try using capture groups. 尝试使用捕获组。 http://www.regular-expressions.info/named.html
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 此外,Expresso对正则表达式问题非常有用http://www.ultrapico.com/ExpressoDownload.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.