Here are some of the most common cases when the expected regex behavior does not match YACC defaults.
. character in regex is not matching newlines
If you use a regular expression to match multiple lines of a commit message, it may not behave as expected because by default, in Java regular expressions, the
. character doesn’t match newlines.
You can work around this in two ways:
Explicitly include the newline character in your regular expression, e.g.
(?s)to the beginning of your regular expression. This enables Pattern.DOTALL, meaning that the
.character also matches newlines.
$ are not matching every line in a multi-line input
By default, these expressions only match at the beginning and the end of the entire input sequence. To enable Pattern.MULTILINE matching mode, add
(?m) prefix to your regex. In multiline mode, the expressions
$ match just after or before, respectively, a line terminator or the end of the input sequence.
Case-sensitive matching is performed.
By default, YACC distinguishes letter cases. Add
(?i) prefix to your regex to perform case-insensitive matching.
The commit message contains unexpected text
Bitbucket automatically inserts commit summaries in pull request merges, which can complicate commit message regex checks.
Disable checking merge commits by enabling the Exclude Merge Commits option from the YACC Exclusions tab.
Turn off commit summaries in pull request commits (Bitbucket 6.7+) as described here.
Update your regex to allow the commit summaries on pull request merge commits.