在 Regex C# 中查找和选择字符串的一部分的语法是什么?
字符串可能是:
string tdInnerHtml = "<strong> You gained 230 Points </strong>
there is going to be more text and some html code part of this
string <a href=http://google.com>Google it here </a>";
// I want to extract 230 from this string using Regx.
// The digits (230) vary for each tdInnerHtml.
// So code would be to look for digits, followed by space, ending with Points
最佳答案
如果空格和 </strong>
标签是一致的,您可以使用以下内容来获得匹配,并且可以使用以下字符串:“品脱在 230-240 点之间,您获得了 230 点”
var match = Regex.Match(tdInnerHtml, @"(?<pts>\d+) Points ?</strong>");
if (match.Success) {
int points = Convert.ToInt32(match.Groups["pts"].Value);
Console.WriteLine("Points: {0}", points);
}
关于c# - 正则表达式选择子字符串的模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9999544/