File: 05.url.t

package info (click to toggle)
libre-engine-re2-perl 0.18%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 440 kB
  • sloc: cpp: 270; perl: 80; makefile: 2; sh: 1
file content (15 lines) | stat: -rw-r--r-- 536 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!perl
use Test::More tests => 3;
use re::engine::RE2;

# From http://daringfireball.net/2010/07/improved_regex_for_matching_urls
my $re = qr{(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))};

my $res = "this is a URL: http://github.com" =~ $re;

ok $res;
is $1, "http://github.com";

my @url = "this is a URL: http://github.com" =~ $re;
is_deeply \@url, ["http://github.com", (undef) x 4];