[英]Extract href ID in html page using regular expression
I was trying to extract ID which is in HTML page within href. 我试图提取href内HTML页面中的ID。 Html looks like below HTML看起来像下面
<p>To register your account, please click the following link:</p>
<p><a href="https://abc-api-test.mywebsites.net:443/#/userreg/99978f1c-4c04-41ac-abcb-5039658a1f52" target="_blank">Complete registration.</a></p>
<p>If you have any questions please do not hesitate to contact us at <a href="mailto:muaccount@aol.net">
Basically I want to extract 99978f1c-4c04-41ac-abcb-5039658a1f52
value from the above. 基本上我想从上面提取99978f1c-4c04-41ac-abcb-5039658a1f52
值。
Thanks 谢谢
Please try this 请尝试这个
// specify Regular expression
Regex pageParser = new Regex(@"href=[""|']https://abc-api-test.mywebsites.net:443/#/userreg/(?<ID>[\S]*?)[""|']", RegexOptions.IgnoreCase | RegexOptions.Multiline);
// extract matches from your HTML
MatchCollection matches = pageParser.Matches(yourHtml);
//Iterate through each match
foreach (var m in matches)
{
var id = m.Groups["ID"].Value;
// do whatever you want with the ID
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.