首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

求大神较如何用正则表达式提取指定字符串

2012-12-28 
求大神较怎么用正则表达式提取指定字符串 string html mapData.push({name:克里斯,memberId:gtty8888

求大神较怎么用正则表达式提取指定字符串


 string html=" mapData.push({
    name:"克里斯",
    memberId:"gtty88888",
wpLink:"http://www.baidu.com/154"


求如何提取 name属性,memberId属性,以及wpLink属性中的值……
PS:求写的详细点,语法还不懂呢……

[最优解释]
$)").Cast<Match>().Select(t => new { name = t.Groups[1].Value, txt = t.Groups[2].Value }).ToArray();
            foreach (var tt in ary)
            {
                Console.WriteLine(tt.name+":"+tt.txt);
            }
[其他解释]
 string html = @" mapData.push({
            name:""克里斯"",
            memberId:""gtty88888"",
        wpLink:""http://www.baidu.com/154";
            var ary = Regex.Matches(html, @"(\w+):""([^""$]+)(""
[其他解释]

string html = @" mapData.push({            
name:""克里斯"",            
memberId:""gtty88888"",        
wpLink:""http://www.baidu.com/154""";
Regex reg = new Regex(@"(?i)mapData.push\({\s*name:""(?<name>[^""]*)"",\s*memberId:""(?<memberId>[^""]*)"",\s*wpLink:""(?<wpLink>[^""]*)""");
MatchCollection mc = reg.Matches(html);
foreach (Match m in mc)
{
   richTextBox2.Text += m.Groups["name"].Value + "\n";
   richTextBox2.Text += m.Groups["memberId"].Value + "\n";
   richTextBox2.Text += m.Groups["wpLink"].Value + "\n";
}
/*-----输出-----
克里斯
gtty88888
http://www.baidu.com/154
*/

[其他解释]

好强…拿回代码学习去了~

热点排行