110,538
社区成员
发帖
与我相关
我的任务
分享
public void testRegex04()
{
string yourStr = @"{$_Type:head_news;Num:3;}
我实在不知道你遇到的文本长什么样,只好自己随便加点文字表示一下了。是这个样子么?你不能吧整个网页贴出来么?或是贴网址
{testpar:head_bbs;Char:4;}";
MatchCollection lines = Regex.Matches(yourStr, "{[^{}]+}");
foreach (Match line in lines)
{
MatchCollection mc = Regex.Matches(line.Value, "(?<=[{;])(?<name>[^:]+):(?<value>[^:;}]+)(?=[;}])");
foreach (Match m in mc)
{
//新手楼主,m.Groups["value"].Value就是你要的内容,你爱转什么格式随便你自己,正则返回的是字符串,
//如果要int就转int,其他就其他,int vn = int.Parse(m.Groups["value"].Value);
MessageBox.Show("name\tvalue" + Environment.NewLine +
m.Groups["name"].Value + "\t" + m.Groups["value"].Value);
}
}
private void button1_Click(object sender, EventArgs e)
{
string yourStr = @"{$_Type:参数1;Num:参数2;}
test line text
{testpar:参数3;Char:参数4;}";
MatchCollection lines = Regex.Matches(yourStr, "{[^{}]+}");
foreach (Match line in lines)
{
MatchCollection mc = Regex.Matches(line.Value, "(?<=[{;])(?<name>[^:]+):(?<value>[^:;}]+)(?=[;}])");
foreach (Match m in mc)
{
MessageBox.Show("name\tvalue" + Environment.NewLine +
m.Groups["name"].Value + "\t" + m.Groups["value"].Value);
}
}
}