CopyCode The Code is as follows: function match_links ($ document ){
Preg_match_all ("'<\ s * A \ s .*? Href \ s * = \ s * ([\ "\ '])? (? (1 )(.*?) \ 1 | ([^ \ s \>] +) [^>] *>? (.*?) </A> 'isx ", $ document, $ links );
While (List ($ key, $ Val) = each ($ Links [2]) {
If (! Empty ($ Val ))
$ Match ['link'] [] = $ val;
}
While (List ($ key, $ Val) = each ($ Links [3]) {
If (! Empty ($ Val ))
$ Match ['link'] [] = $ val;
}
While (List ($ key, $ Val) = each ($ Links [4]) {
If (! Empty ($ Val ))
$ Match ['content'] [] = $ val;
}
While (List ($ key, $ Val) = each ($ Links [0]) {
If (! Empty ($ Val ))
$ Match ['all'] [] = $ val;
}
Return $ match;
}
This is mainly about regular expressions. Below is a multi-test regular expression under Asp.net.
Get the Page Link regularCopy codeThe Code is as follows: Public String gethref (string htmlcode)
{
String matchvale = "";
String Reg = @ "(H | H) (R | r) (E | E) (F | f) * = * ('| "")? (\ W | \/| \. |: |-| _) +) ('| "" | * |> )? ";
Foreach (Match m in RegEx. Matches (htmlcode, REG ))
{
Matchvale + = (M. Value). tolower (). Replace ("href =", ""). Trim () + "| ";
}
Return matchvale;
}