Gets the top-level domain name code in the string
<body>
<textarea id= "B" >
Http://xxx.com/123.html
Http://www.xxx.com/123.html
Http://www.xxx.com.cn/123.html
Http://www.xxx.org/123.html
Http://a.www.xxx.net/123.html
Http://a.b.www.xxx.com/123.html
Http://a.b.c.www.xxx.net.cn/123.html</textarea>
<script type= "text/web Effects" >
var s = b.value.split ("n");
var a = [];
var re = new RegExp ("Http://.*?" ( [^.] +. (com.cn|org.cn|net.cn| [^.] +))/.+ "," I ");
for (var i = 0; i < s.length i + +) {
if (Re.test (S[i])) {
A.push (S[i].match (re) [1]);
}
else{
A.push ("Not Legal domain name");
}
}
Alert (A.join ("n"));
</script>
</body>
PHP Tutorial Practices
<?php
$arr = Array (
"Http://xxx.com/123.html",
"Http://www.xxx.com/123.html",
"Http://www.xxx.com.cn/123.html",
"Http://www.xxx.org/123.html",
"Http://a.www.xxx.net/123.html",
"Http://a.b.www.xxx.com/123.html",
"Http://a.b.c.www.xxx.net.cn/123.html"
);
$re = "/http://.*?" ([^.] +. (com.cn|org.cn|net.cn| [^.] +))/.+/";
$ra = Array ();
for ($i = 0; $i < count ($arr); $i + +) {
if (Preg_match ($re, $arr [$i])) {
Preg_match_all ($re, $arr [$i], $res, Preg_pattern_order);
$ra [] = $res [1][0];
}
else{
$ra [] = "is not a legal domain name";
}
}
Print_r (Join ("RN", $ra));
?>