use strict;
my $str = '=== Cette page est utilisé pour tester un maximum de scénarios différents pour l\'outil WikiRef. ===
=== <u>Merci de ne pas y toucher</u> ===
<ref>Melon busk + shorten domain https://www.youtube.com/watch?v=2j3p_aDMTNg</ref>
<ref>vidéo privé http://www.youtube.com/watch?v=yZ-K7nCVnBI&playnext_from=TL&videos=osPknwzXEas&feature=sub</ref>
<ref>rick roll http://youtu.be/dQw4w9WgXcQ?feature=youtube_gdata_playe</ref>
<ref>ajout source redirect home page - http://youtube.com/watch?vi=dQw4w9WgXcQ&feature=youtube_gdata_player</ref>
<ref>rick roll avec share https://youtube.com/shorts/dQw4w9WgXcQ?feature=share\'</ref>
<ref>Video indisponible (pas TOS, pas privé) - https://www.youtube-nocookie.com/embed/up_lNV-yoK4?rel=0%2C</ref>
<ref>lien de chaine https://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo</ref>
<ref>chaine indisponnible http://www.youtube.com/ytscreeningroom?v=NRHVzbJVx8I</ref>
<ref>video indisponnible https://www.youtube.com/watch?v=yZ-K7nCVnBI&playnext_from=TL&videos=osPknwzXEas&feature=sub</ref>
<ref>Embedded video https://www.youtube.com/embed/nas1rJpm7wY?rel=0</ref>
<ref> Multiple url reference [https://www.youtube.com/watch?v=ubNF9QNEQLA, https://www.youtube.com/watch?v=ubNF9QNEQLA]</ref>
<ref> nowiki referefence <nowiki>https://www.youtube.com/watch?v=ubNF9QNEQLA</nowiki></ref>
<references />
';
my $regex = qr/\b(?<url>(https?:.//?|www\.).*?)(?:</ref>)/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