c# - Filter a mobile number in a string -
i want catch info webpage using html agility pack. info want use :
exp1: 22391021 - 09198606027 - 88345027
exp2: 22252554 - 29458456 - 09365861449
exp3: chiako.com 09123937651 - 88424554 (4 line)
and input parameters foreach method.
how can catch mobile phone structure ( 09xxxxxxxxx ) ? below examples:
1- 09198606027
2- 09365861449
3- 09123937651
and put parameter(s).
my code:
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; } }
try match string regular expression:
var match = regex.match(node.innertext, @"09\d{9}"); if (match.success) { string name = match.value; // matched phone number }
if expect several phone numbers in string, can use nextmatch method:
while (match.success) { string name = match.value; match = match.nextmatch(); }
Comments
Post a Comment