use strict;
my $str = 'socks://www.example.com
10.1.1.1
10.1.1.2/4
10.1.1.3/0
10.1.1.0/8
10.1.1.5/32
10.1.1.6/35
10.1.1.7/36000
10.1.1.8/abcd
10.1.1.9-10.1.1.10
user:pass@zxuz.com
user@proxy.brew.opendnstest.com/customBlockUserInfo
user:@proxy.brew1.opendnstest.com/customBlockUserInfo
user:password@proxy.brew2.opendnstest.com/customBlockUserInfo
ftp://cnn.example.com&story=breaking_news@foobar.com/top_story.htm
foo.com:8080/bar/baz
asdfasdf.com/foo/b%20ar
https://example.com/archive/*/http://somesite.com
';
my $regex = qr/^(?:[a-z][0-9a-z-.+]*:\/\/)?((?:(?:[a-z\u00a1-\uffff0-9_]+-?)*[a-z\u00a1-\uffff0-9_]+)(?:\.(?:[a-z\u00a1-\uffff0-9_]+-?)*[a-z\u00a1-\uffff0-9_]+)*(?:\.(?:[a-z0-9\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/.*)?(?:\?.*)?(?:\#.*)?$/mip;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html