use strict;
my $str = '## Should Pass
build: test
chore(topic): descriptoin
chore(junk): that\'s better
¯\\_(ツ)_/¯: descriptoin
feat: some with-hyphen
### should pass with breaking change
feat!: monkeys are the best for animal testing
build(three)!: test
Merge words
### Failed to match test
Merge
monkey(dog): no
junk
### Partials that should fail
build(with colon): must include colon. <<< fails number four
build(one) <<< must have descriptoin and must have colon
feat!:dogs are better for animal testing << give me your whitespace
build <<< thould fail, not allowed end of line
build(: <<< should fail
build(words):noSPace <<< should fail
build(two)asdfadfadasdf_this is a failure
build(<> : dda!sd): test <<< should this fail?
build(example:module)!: test subject <<< that should fail too
¯\\_(ツ)_/¯[type]:descriptoin
';
my $regex = qr/^(?<type>build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|¯\\_\(ツ\)_\/¯)(?<scope>\(\w+\)?((?=:\s)|(?=!:\s)))?(?<breaking>!)?(?<subject>:\s.*)?|^(?<merge>Merge \w+)/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