use strict;
my $str = 'https://regex101.com/
https://www.variables.sh/complex-regular-expression-examples
https://search.brave.com/search?q=regex+challenges&source=desktop
https://web.whatsapp.com/
https://www.youtube.com/watch?v=fc_RvxTtIwc
https://text-auditor.netlify.app/
https://github.com/Dashrath-Sharma
http://github.com/Dashrath-Sharma
https://onecompiler.com/javascript/3zqzyu2g4
http://localhost:3000/
https://www.codingame.com/clashofcode/clash/report/3342454a92e4c660d772438bac8b2ef73de3c8f
https://react.dev/learn/thinking-in-react
https://dapp-world.com/course/introduction-to-solidity-Ynws/working-of-traditional-dapps-compared-to-dapps/reading
http://www.google.com
https://www.google.com
http://google.com
https://google.com
http://www.google.com/
https://www.google.com/
http://google.com/
https://google.com/
http://www.google.com/index.html
https://www.google.com/index.html
http://google.com/index.html
https://google.com/index.html
';
my $regex = qr/^(?:https?:\/\/)?(?:www\.)?[\d\w\.-]+(?:\.|:)(?:[a-z\.]{2,6}|\d+)\/?.*$/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