use strict;
my $str = '*** Match odds or A-M
(.*\\d*[13579]\\.article)|(.*[a-d|[f-m]$)
https://edu.rsc.org/science-research/salt-crystal-grows-legs/4012581.article
edu.rsc.org/45.article
edu.rsc.org/weuvkee/a
edu.rsc.org/weuvkee/f
****** Don\'t match
https://edu.rsc.org/ideas/5-ways-to-explain-titration/4012500.article?utm_source=house-list&utm_medium=email&utm_campaign=monthly-alert
https://edu.rsc.org/feature/making-materials-from-biomass/4012606.article
https://edu.rsc.org/eic/classroy
https://edu.rsc.org/wibble/chips/stuff/science
edu.rsc.org
*** Match evens or N-Z
(.*\\d*[02468]\\.article)|(.*[n-z]$)
https://edu.rsc.org/ideas/5-ways-to-explain-titration/4012500.article?utm_source=house-list&utm_medium=email&utm_campaign=monthly-alert
https://edu.rsc.org/feature/making-materials-from-biomass/4012606.article
https://edu.rsc.org/eic/classroy
https://edu.rsc.org/wibble/chips/stuff/science
****** Don\'t match
https://edu.rsc.org/science-research/salt-crystal-grows-legs/4012581.article
edu.rsc.org/45.article
edu.rsc.org/weuvkee/a
edu.rsc.org/weuvkee/f';
my $regex = qr/(.*\d*[13579]\.article)|(.*[a-d|[f-m]$)/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