use strict;
my $str = '100.200.300
100.200.300.7068-ls170
v100.200.300-ls213
version-100.200.300
version-100.200.300-ls180
version-100.200.300.11111
100.200.300.7068-ls170
nigthly-100.200.300
nightly-100.200.300.3604-ls587
100.200.300-development
100.200.300-develop
100.200.300-nigthly
';
my $regex = qr/^
# Build information should not contain dev and nightly stuff:
(?!.*(nig(ht|th)ly|develop|development))
# Optional compatibility prefix "version-" or "v":
(?<compatibility>[a-z]*-|v)?
# Major, minor and patch numbers:
(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)
# Capture the optional build information:
(?:
[\.-]?
(?<build>.*)
)?
$/mxp;
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