求大神较怎么用正则表达式提取指定字符串
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
*/
[其他解释]
好强…拿回代码学习去了~