得到一html 字符串 其他的标签省略,关键的地方是:
<li><a href="/ArcGIS/rest/services/CSP_Imagery_World_2D/MapServer">中国</a> (MapServer)</li>
<li><a href="/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer">美国</a> (MapServer)</li>
<li><a href="/ArcGIS/rest/services/ESRI_ShadedRelief_World_2D/MapServer">日本</a> (MapServer)</li>
如何从中 提取出 中国 美国 日本 这三个字符串呢??谢谢
<li><a href="/ArcGIS/rest/services/CSP_Imagery_World_2D/MapServer">中国</a> (MapServer)</li>
<li><a href="/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer">美国</a> (MapServer)</li>
<li><a href="/ArcGIS/rest/services/ESRI_ShadedRelief_World_2D/MapServer">日本</a> (MapServer)</li>
如何从中 提取出 中国 美国 日本 这三个字符串呢??谢谢
不行就直接用'<'和'>'做拆分
str.split('<')[2].split('>')[1]
应该就可以了
string pattern = @"(?<=<[a].*>)(.*)(?=</a>)"; MatchCollection matches = Regex.Matches(input, pattern);
foreach (Match match in matches)
{
Console.WriteLine(match.Groups[1].Value);
}
"<li><a href=\"/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer\">美国</a> (MapServer)</li>"+
"<li><a href=\"/ArcGIS/rest/services/ESRI_ShadedRelief_World_2D/MapServer\">日本</a> (MapServer)</li>"; string pattern = "(?<=MapServer\">)(.*?)(?=</a>)"; MatchCollection matches = Regex.Matches(input, pattern);
foreach (Match match in matches)
{
Console.WriteLine( match.Groups[1].Value);