正则表达式高手请帮忙!!
例如是这样的
Host: storeimages.apple.com
Accept: imagepng=123;image=12322222222222222222222222222222212313213132131313
1212132132132131321321313
Host:
Accept: storeimages=\;apple=/;com=1
Accept: gzip12=11; deflate=\
Connection: keep-alive
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7\
我要获取Accept:开头的字符 提出来 怎么办?最后
[解决办法]
(?<=Accept\\:)\\w+
[解决办法]
- C# code
Match match = Regex.Match(str,"Accept:([^\r\n]+)", RegexOptions.IgnoreCase); if(match.Success) { string value = match.Groups[1].Value; }
[解决办法]
- C# code
(?i)Accept:.+
[解决办法]
- C# code
List<KeyValuePair<string,string>> keyValueList = new List<KeyValuePair<string,string>>(); MatchCollection matches = Regex.Matches(str,"Accept:([^\r\n]+)", RegexOptions.IgnoreCase); foreach(Match match in matches) { string value = match.Groups[1].Value.Trim(); MatchCollection matches1 = Regex.Matches(value, @"([^=]+)=([^;]+);?", RegexOptions.None); foreach(Match match1 in matches1) { keyValueList.Add(new KeyValuePair<string,string>(match1.Groups[1].Value,match1.Groups[2].Value)); } } foreach(KeyValuePair<string,string> item in keyValueList) { // 穷举keyValueList可以提取所有Accept里面的键和值 }