regex – RegExp testing fails when string is validated in RegExp tools
Bash regexp does not know \n to be a new line character. The [^\n] is just a [^n] so the lines which your script marks as invalid – have “n” in them (“checking”, “new”).
The new line bash regexp do recognize is actually $ – end of the line.
Another point – your test strings do not have \n characters in them, so there is no real need to check for its absence – hence a simple is enough, which would mean that complex pattern ends with colon, space and you have something after that. No real need to end the pattern with $ since it already will go up to the end of a string.
Said that… if your just hit Enter inside the pattern, you will get a string like:
local pattern="^(feat|fix|docs|style|refactor|test|chore)\([a-zA-Z0-9._-]+\): [^
]+$"
But bush (or at least some versions of it) will see it as a single string with a \n and do a real “no \n inside the string”.
It is possible – yes. Is it better than simple .+ – definitely not. But as a funny feature and possible way to confuse people – yes.
Read more here: Source link
