ruby - Regex for Git commit message -


i'm trying come regex enforcing git commit messages match format. i've been banging head against keyboard modifying semi-working version have, can't work want. here's have now:

/^([a-z]{2,4}-[\d]{2,5}[, \n]{1,2})+\n{1}^[\w\n\s\*\-\.\:\'\,]+/i 

here's text i'm trying enforce:

ab-1432, abc-435, abcd-42  here multiline description, following blank  line after jira issue ids - maybe bullet points, either dashes * or asterisks 

currently, matches that, match if there's no blank line after issue ids, , if there's multiple blank lines after.

is there anyway enforce that, or have live it?

it's pretty ugly, i'm sure there's more succinct way write out.

thanks.

your regex allows \n 1 of possible characters after required newline, that's why matches when there multiple.

here's cleaned regex:

/^([a-z]{2,4}-\d{2,5}(?=[, \n]),? ?\n?)+^\n([-\w\s*.:',]+\n)+/i

notes:

  • this requires @ least 1 [-\w\s*.:',] character before next newline.
  • i changed issue ids have 1 possible comma, space, , newline, in order (up 1 of each). can use lookaheads? if so, added (?=[, \n]) make sure issue id followed @ least 1 of characters.
  • also notice many of characters don't need escaped in character class.

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -