re = /^(?<type>build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|¯\\_\(ツ\)_\/¯)(?<scope>\(\w+\)?((?=:\s)|(?=!:\s)))?(?<breaking>!)?(?<subject>:\s.*)?|^(?<merge>Merge \w+)/m
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
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html