【发布时间】:2021-05-27 03:56:00
【问题描述】:
我一直在尝试从一些 HTML 数据中提取单个值,但我无法完全专注于我正在寻找的部分:
我要读取的行是:
<span class="temp">5</span>
还有很多不同类的“span”标签,所以我只需要接受“temp”类, 然后获取值?
我真的没有使用 Regex 的经验,但一直在尝试弄清楚。 以下是我尝试过的一些线路:
//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp"">(.+?)<", RegexOptions.None);
//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp"">\s*(.+?)\s*</span>", RegexOptions.Singleline);
//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp""> (.*?) </span> ", RegexOptions.Singleline);
//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp"">(([^<]|<[^\/]|<\/[^s]|<\/s[^p]|<\/sp[^a]|<\/spa[^n]|<\/span[^ \t >])*)</span>", RegexOptions.Singleline);
//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp"">\s*([^<])\s*</span>", RegexOptions.Singleline);
//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp"">\s*(<.*?>) * ([^<] *)\s*</span>", RegexOptions.Singleline);
//MatchCollection data = Regex.Matches(searchData, @"(?<=<span\s *class=""temp""[^><]*>\s*)[^<>]*", RegexOptions.Singleline);
//MatchCollection data = Regex.Matches(searchData, @"(?<=<span\s*class=""temp""[^><]*>\s*)[^<>]*", RegexOptions.Singleline);
//MatchCollection data = Regex.Matches(searchData, @"(?<=<span\s*class=""temp"">\s*)*", RegexOptions.Singleline);
//MatchCollection data = Regex.Matches(searchData, @"<span[^>] *> (.*?) </ span>", RegexOptions.Singleline);
//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp""></span>", RegexOptions.Singleline);
//MatchCollection data = Regex.Matches(searchData, @"<span class=""temp""></span>", RegexOptions.Singleline);
感谢您提供的任何帮助! 道格
【问题讨论】:
-
你试过这个
@"<span class=""temp"">[^<>]*</span>"吗? -
嗨 gilmutdinov,不幸的是,这也不起作用....
-
嗨磁控管,谢谢。我会找到另一种方法来提取我正在寻找的东西。谢谢。
标签: c# html regex attributes tags