string oldstring="最高:<span id="bfn_hi_600050.sh" class="color_red">6.32</span>最低:";string newString="";//我想通过正则得到6.32
我想得到6.32怎么做?其中“最高:”和“最低”的位置是固定的。
再来一个例子
string oldstring="最高:<span id="span1">10000</span>最低:";string newString="";//我想通过正则得到10000
调试欢乐多
@"(?i)(?<=最高:<span\b[^>]*>)[^<]+(?=</span>最低:)"
Regex _regex = new Regex(@".*最高.*>(?<max>.*)</span>最低:");
MatchCollection _matchCollection = _regex.Matches(strText); foreach (Match objMatch in _matchCollection)
{
Console.WriteLine(objMatch.Groups["max"].Value);
}
string oldstring="最高:<span id="span1">10000</span>最低:";
string newString="";//我想通过正则得到10000
Match match = Regex.Match(oldstring, @"最高:<span[^>]+>(?<number>[^<]+)</span>最低:", RegexOptions.IgnoreCase);
if (match.Success)
{
newString=match.Groups["number"].Value;
}
string newString="";//我想通过正则得到10000
Match match = Regex.Match(oldstring, @"最高:<span[^>]+>(?<number>[^<]+)</span>最低:", RegexOptions.IgnoreCase);
while (match.Success)
{
newString += match.Groups["number"].Value + ",";//每项之间用逗号隔开
match = match.NextMatch();//批配下一项
}