【发布时间】:2019-06-04 10:56:25
【问题描述】:
我有一个类似这样的字符串,这个字符串来自一个很长的 HTML 页面源:
"entity_id":"1234567890"
我正在尝试像这样解析数字1234567890,但无法解析id:
var re = new Regex("\"entity_id\":\"([0 - 9] +)\"");
var match = re.Match(task.Result);
var id = match.Success ? match.Value : string.Empty;
Console.WriteLine(id);
为什么它没有被解析以及如何修复它?
【问题讨论】:
-
这看起来很像来自较大 JSON 内容的片段。这是 JSON 吗?
-
不,它包含在页面 html 源代码中
-
带正则表达式:
var id = Regex.Match(s, "\"entity_id\":\"([0-9]+)\"")?.Groups[1].Value. -
干得好。工作