Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
use strict;
use warnings;
#URI specification from RFC 2396 : http://www.ietf.org/rfc/rfc2396.txt
my $reserved = ';?:@&=+\\$,'; #removed / from spec
my $unreserved = q{\\-_!~*'()a-zA-Z0-9}; #removed . from spec
my $escaped = '%[a-fA-F0-9]{2}';
#a single allowed character or a complete escape sequence
my $allowed_all = qr{(?:[$unreserved$reserved./]|(?:$escaped))};
my $allowed_limited = qr/(?:[$unreserved$reserved]|(?:$escaped))/;
#optionally, could add gopher: mailto: news: telnet:
my $start = qr{(?:http:|www.|ftp:)};
#easy one is where it starts with something predictable from $start
my $easy = qr/$start$allowed_all+/;
#attempts to match domain. multiple times, then a 2 or 3 character top level domain
#examples: com edu uk jp
#there are some exotic tld's that this wouldn't catch, like .museum or .info,
#but they're pretty rare yet so I'll ignore them
my $hard = qr/(?:$allowed_limited+\.)+$allowed_limited{2,3}(?:\/$allowed_all*)?(?!$allowed_all)/;
#make a little test suite of link-like and not-link-like lines to run it on
$_ = <<'EOF';
It needs to recognize, links in the following patterns:
subdomain.mydomain.com/page1.html
http://subdomain.mydomain.com/page1.html
www.mydomain.com/page1.html
http://www.mydomain.com/page1.html
subdomain.mydomain.com
Any ideas?
But, certain other combinations are being filtering into hyperlinks as well, such as:
>.<
Q.Letter
Some combinations don't, like the following:
!.!
A.B
Any thoughts?
EOF
#find an easy one or a hard one
s/($easy|$hard)/<a href="$1">$1<\/a>/g;
print;