[請益] 請教關於網址的正規表示法問題
有一個取domain name的簡單範例如下:
<?php
$pettern = '/^http\:\/\/(.+)\/(.*)/i';
$subject = "http://www.php.net/index.html";
preg_match($pettern, $subject, $match);
$host = $match[1];
preg_match('/[^.]+\.[^.]+$/', $host, $match);
echo 'the domain name is : '. $match[0];
?>
最近剛碰正規表示法,其中上面標色的那段一直無法參透
目前只知道是取[^.]+\.[^.]+為結尾的字串,得到一個xxx.xxx的字串
最後會從www.php.net變成php.net,
但[^.]+ 這串實在無法了解
我的理解,小數點是指一個任意字元,^是指not,但後面又加了+
組合在一起變成 "至少有一個以上的非任意字元" 就完全不懂了@@
希望板上的前輩可以幫忙指點一下,萬分感謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 175.180.119.53
※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1451900267.A.5B5.html
→
01/04 17:44, , 1F
01/04 17:44, 1F
→
01/04 17:44, , 2F
01/04 17:44, 2F
→
01/04 18:03, , 3F
01/04 18:03, 3F
→
01/04 18:21, , 4F
01/04 18:21, 4F
→
01/04 18:22, , 5F
01/04 18:22, 5F
→
01/04 19:33, , 6F
01/04 19:33, 6F
→
01/04 19:34, , 7F
01/04 19:34, 7F
→
01/05 16:45, , 8F
01/05 16:45, 8F