当前位置: 代码迷 >> ASP.NET >> 怎么用正则表达式提取值来
  详细解决方案

怎么用正则表达式提取值来

热度:4667   发布时间:2013-02-25 00:00:00.0
如何用正则表达式提取值来
<$if:classid value="640518574713"> 也可能是这样的格式 <$if:name value="333">

 如上面的字符串

classid 和 640518574713 是变化的 我怎么 提出值来的呢?

我写了个 但都不行
 Regex reg = new Regex(@"<$if:(?<name>[.*]\s\b) value=\""(?<value>[.*]+)\"">", RegexOptions.Compiled);
  Match m = reg.Match(mass);
  string name = m.Groups["name"].Value.Trim();
  string value = m.Groups["value"].Value.Trim();

该如何写呢?

------解决方案--------------------------------------------------------
C# code
        string s = @"<$if:classid value=""640518574713""><$if:name value=""333"">";        MatchCollection matches = Regex.Matches(s, @"(?is)<\$if:(?<name>classid|name)\s+value=""(?<value>.*?)"">");        foreach (Match match in matches)        {            Response.Write(match.Groups["name"].Value + "<br/>");            Response.Write(match.Groups["value"].Value + "<br/>");        }