实现以下任务的正则表达式模式是什么
数据格式(模式)
anyword:anycharcters;
示例输入
msg:"c# 6.0 is good";sid:201;classtype:object oriented;.net,ado.net,other messages
预期输出(匹配组)
msg:"c# 6.0 is good"; ----------> 1
sid:201;--------------------->2
classtype:object oriented;---------->3
答案 0 :(得分:1)
您不需要在此处使用正则表达式匹配器。相反,您可以尝试用分号分隔符分割字符串:
string value = "msg:\"c# 6.0 is good\";sid:201;classtype:object oriented;.net,ado.net,other messages";
string[] lines = Regex.Split(value, ";");
foreach (string line in lines) {
Console.WriteLine(line);
}
答案 1 :(得分:1)
答案 2 :(得分:1)
string g = @"msg:""c# 6.0 is good"";sid:201;classtype:object oriented;.net,ado.net,other messages";
foreach (Match match in Regex.Matches(g, @"(.*?):([^;]*?;)", RegexOptions.IgnoreCase))
Console.WriteLine(match.Groups[1].Value + "--------"+match.Groups[2].Value);
输出:
msg--------"c# 6.0 is good";
sid--------201;
classtype--------object oriented;