过滤字符串中的手机号码
本文关键字:手机号码 字符串 过滤 | 更新日期: 2023-09-27 18:10:31
我想从使用html敏捷包的网页中获取一些信息。但是我想使用的信息是这样的:
Exp1: 22391021 - 09198606027 - 88345027
Exp2: 22252554 - 29458456 - 09365861449
Exp3: chiako.com 09123937651 - 88424554 (4 Line)
并使用foreach方法将其输入到某些参数中。
我怎么能只接这个结构(09xxxxxxxxx)的手机?就像下面的例子:
1 - 09198606027 2 - 09365861449 3 - 09123937651并将其放入参数
我代码:public void GetingInformarion()
{
string PageLoad = "http://rahnama.com/cat/index/id/38093/%D8%A7%D8%B9%D8%B2%D8%A7%D9%85-%D8%AF%D8%A7%D9%86%D8%B4%D8%AC%D9%88";
HtmlWeb hw = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = hw.Load(PageLoad);
HtmlNodeCollection nodes1 = doc.DocumentNode.SelectNodes("//p[@style='margin:0;']/span");
foreach (HtmlNode node in nodes1)
{
string Name = node.InnerText;
}
}
尝试用正则表达式匹配字符串:
var match = Regex.Match(node.InnerText, @"09'd{9}");
if (match.Success)
{
string Name = match.Value; // your matched phone number
}
如果你希望在字符串中有多个电话号码,你可以使用NextMatch方法:
while (match.Success)
{
string Name = match.Value;
match = match.NextMatch();
}
您可以使用Regex查找具有特定模式的所有匹配项。请查看:印度手机号码的正则表达式,以获取手机号码的相关正则表达式。