string dirResults="本地连接:Node IpAddress: [192.168.0.189] Scope Id: [] NetBIOS Remote Machine Name Table Name Type Status --------------------------------------------- STAR <00> UNIQUE Registered STAR <20> UNIQUE Registered WWW <00> GROUP Registered WWW <1E> GROUP Registered MAC Address = 00-02-3F-E7-FE-E8";我想从字符串dirResults的最后获得MAC地址,参考代码:
dirResults=dirResults.Replace("\r","").Replace("\n","").Replace("\t","");               Regex reg=new Regex("Mac[ ]{0,}Address[ ]{0,}=[ ]{0,}(?<key>((.)*?)) __MAC",RegexOptions.IgnoreCase|RegexOptions.Compiled); 
               Match mc=reg.Match(dirResults+"__MAC");            if(mc.Success) 
            { 
                return mc.Groups["key"].Value; 
           } //这个代码不能正确获得MAC,请高手指点正确代码。谢谢!

解决方案 »

  1.   

    我说的太复杂?简单的说,我获得一个有MAC地址的字符串,我就要获得MAC地址,怎么做?
    dirResults="Registered MAC Address = 00-02-3F-E7-FE-E8";
      

  2.   


    string  s = "(\\w\\w)-(\\w\\w)-(\\w\\w)-(\\w\\w)-(\\w\\w)-(\\w\\w)";
    Regex re = new Regex(s,RegexOptions.IgnoreCase|RegexOptions.Singleline);
    System.Text.RegularExpressions.MatchCollection
    mc = re.Matches(youstr);foreach(Match m in mc)
    {
    //m.Value
    Console.WriteLine("------"+m.Value+"---------");
    }
    Console.ReadLine();