use strict;
my $str = '<p>Intro:G,C,D D, A, Em, Eb Ebb G G,C,D</p>
A,B,C <p><br />
Verse 1:</p> <p> D A Em <br />
Yeah I\'ve iced down a few thousand beers in my days<br />
G <br />
You put down twice as many<br /> D A Em <br />
C9 G C#/Db C# Dsus2sus4
Dmaj13#11
Bmaj13#11
A7(b5,#9)
A7#9
B-5
#sus #maj #min #aug';
my $regex = qr/\b(?:G,C,D|A,B,C|E,C,D)|(?:[ABCDEFG](?:#|b)?)(?:\/[ABCDEFG]b)?(?:(?:(?:maj|min|sus|add|aug|dim)(?:\d{0,2}(?:#\d{1,2}|sus\d)?)?)|(?:m\d{0,2}(?:(?:maj|add|#)\d{0,2})?)|(?:-?\d{0,2}(?:\([^)]*\)|#\d{1,2})?))?/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