use strict;
my $str = '
baamid-admin-api-ecs-service-dev
baamid-admin-api-ecs-service-qa
baamid-admin-api-ecs-service-qb
baamid-admin-api-ext-ecs-service-dev
baamid-admin-api-ext-ecs-service-qb
bxid-duende-ecs-service-dev
bxid-duende-ecs-service-qa
bxid-duende-ecs-service-qb
bxid-ecs-service-dev
bxid-ecs-service-qa
bxid-ecs-service-qb
bxid-ext-ecs-service-dev
bxid-ext-ecs-service-m-dev
bxid-ext-ecs-service-m-qa
bxid-ext-ecs-service-m-qb
bxid-ext-ecs-service-qa
bxid-ext-ecs-service-qb
policy-server-admin-ecs-service-dev
policy-server-admin-ecs-service-qa
policy-server-admin-ecs-service-qb
policy-server-agent-api-dev
policy-server-agent-api-qa
policy-server-agent-api-qb
policy-server-ecs-service-dev
policy-server-ecs-service-m-dev
policy-server-ecs-service-m-qa
policy-server-ecs-service-m-qb
policy-server-ecs-service-qa
policy-server-ecs-service-qb
userprofilesservice-dev
userprofilesservice-ecs-service-qa
userprofilesservice-ecs-service-qa1a
userprofilesservice-ecs-service-qa2a
userprofilesservice-ecs-service-qa33a
userprofilesservice-ecs-service-qa5b
userprofilesservice-ecs-service-qb
userprofilesservice-ecs-service_r1
userprofilesservice-ecs-service_r2
userprofilesservice-ecs-service_x
userprofilesservice-ecs-service_y';
my $regex = qr/\-(?:dev|qa)[0-9]*[ab]/p;
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