use strict;
my $str = 'https://medium.com/@s.vive00/7-changes-i-experienced-after-going-1-week-without-added-sugar-9bc48b667f87?source=email-8f87fbd013ca-1581664260785-digest.weekly------0-58------------------2882ae9f_a61e_4d5c_9f87_24f3e0d54cc9-1-----§ionName=top
https://medium.com/@DrAyala/exercise-is-the-answer-heres-why-it-s-a-weight-loss-underperformer-8b64103b8c8f?source=email-8f87fbd013ca-1581664260785-digest.weekly------1-59------------------2882ae9f_a61e_4d5c_9f87_24f3e0d54cc9-1-----§ionName=top#Fragment-identifier
https://www.medium.com/@DrAyala/exercise-is-the-answer-heres-why-it-s-a-weight-loss-underperformer-8b64103b8c8f?source=email-8f87fbd013ca-1581664260785-digest.weekly------1-59------------------2882ae9f_a61e_4d5c_9f87_24f3e0d54cc9-1-----§ionName=top#Fragment-identifier
http://www.yoursite.com/path/to/file.mp3
http://example.com/data.csv#row=4
http://example.com/bar.webm#t=40,80&xywh=160,120,320,240
example.com/data.csv#row=4
example.co.uk/data.csv#row=4';
my $regex = qr/^(?<Scheme>[file|ftp|https{0,1}|ldap|telnet]+:\/{2})?(?<Subdomain>[a-zA-Z0-9-]{0,4}\.)?(?<Domain>\w+\.\w+\.?\w+\/)(?<Subdirectory>@[\w.]+\/)?(?<Path>[\w_~.-]+\/?[\w_-]+\/{0,1}?[\w_~.-]+)(?<Query>[%?&;].[\w&_~.=-]+)?(?<Fragment>#?[\/\w_-~.,=&-]+)?$/mp;
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