c#字符串使用正则表达式示例
1.截取字符串中指定内容
{"weatherinfo":{"city":"北京","cityid":"101010100","temp":"-4","WD":"西北风","WS":"2级","SD":"29%","WSE":"2","time":"09:40","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB"}}
stringpattern="{\"weatherinfo\":(.*)}";
varresult=Regex.Match(weatherQueryResult,pattern,RegexOptions.IgnoreCase).Groups;
2.截取字符串中的数字 返回结果123,12 3.截取字符串中的字母 返回结果为B/F/E
返回结果为{"city":"北京","cityid":"101010100","temp":"-4","WD":"西北风","WS":"2级","SD":"29%","WSE":"2","time":"09:40","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB"}
strings="B123-C12";
MatchCollectionvMatchs=Regex.Matches(s,@"(\d+)");
vMatchs[0].Value
stringstr="呵呵呵呵aB-cFe-sdfEww";
MatchCollectionm=Regex.Matches(str,@"[A-Z]+");//小写字母为a-z大小写混合为a-zA-Z
相关文章