use strict;
my $str = 'RY4 Asian Flavor 10-15%
RY4 Double Flavor 5%-15%
Smooth Flavor 2 drops per 5 ml
Spearmint Flavor <5% Very Strong
Strawberries and Cream Flavor 10-12%
Strawberry Flavor 3%-15%
Strawberry Kiwi 20% 1/5
Strawberry Ripe 15%
Sweet Cream Flavor 5-10% 4/5 recommended for combining fake butter taste
Sweet Tart: 10% 5/5 Tastes more like Smarties
Sweetener 2%-6%
Tangerine Flavor (oil based) 1-5% 5/5
Tiramisu Flavor 2-5% VERY strong
Toasted Almond Flavor 15%';
my $regex = qr/([\S]*)[\s]+([\S]*[\s]+[\S]*)[\s]+([0-9]{1,2})\%/ip;
if ( $str =~ /$regex/ ) {
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