正規表現で、ソーシャルブックマーカブルな URL かそうでないかを判定する - にぽたん研究所

February 05, 2009

このエントリーをはてなブックマークに追加
#!perl

use strict;
use warnings;
use Perl6::Say;

my $PRIV_IP_RE = qr{^https?://
    \b(?:
	10\.(?:\d\d?|1\d\d|2(?:[0-4]\d|5[0-5]))|  # class A
	172\.(?:1[6-9]|2\d|3[01])|                # class B
	192\.168                                  # class C
    )
    \.(?:\d\d?|1\d\d|2(?:[0-4]\d|5[0-5]))
    \.(?:\d\d?|1\d\d|2(?:[0-4]\d|5[0-5]))\b
}xi;

for my $url (qw(http://10.10.2.60/ http://www.google.com/)) {
    say "$url IS " . ($url =~ $PRIV_IP_RE ? "NOT BOOKMARKABLE" : "BOOKMARKABLE");
}
結果:
http://10.10.2.60/ IS NOT BOOKMARKABLE
http://www.google.com/ IS BOOKMARKABLE
参考:
おまいの iTunes も共有汁 - にぽたん研究所
はてなブックマーク - うごメモはてな - メモからはじまる新しいコミュニケーション!

nipotan at 18:07 | Comments(0) | TrackBack(0) | 技術 
このエントリーをはてなブックマークに追加

Trackback URL for this entry

Post a comment

Name:
URL:
  Remember info?: Rate: Face    Star