-
Notifications
You must be signed in to change notification settings - Fork 95
Description
Hi,
I am currently trying to parse our issues from the commit messages and that works. But because our format is [ABC-1234] we get [ABC-1234] as a result because the issue matcher returns group() (=group(0)).
In regex otherwise we could define non-capturing groups ( "(?:pattern)" ) which would result in this matching pattern NOT returned by the group.
The only difference for the default regex would be that it always have to be in one group aka surrounded by brackets.
So \b[a-zA-Z]([a-zA-Z]+)-([0-9]+)\b
would be (\b[a-zA-Z]([a-zA-Z]+)-([0-9]+)\b)
and group(1) for ABC-1234 would return ABC-1234
and in our case we could use (?:\[)(([a-zA-Z](?:[a-zA-Z]+)-(?:[0-9]+)))(?:\])
and group(1) for [ABC-1234] would return ABC-1234
This way there would be more flexibility in the regex. The other, more complicated approach would be to also add a parameter for which group should be returned or return all groups or something but in my understanding group(1) should do the trick for the default and most other cases as you could just filter out everything else.
Code change would be here:
git-changelog-lib/src/main/java/se/bjurr/gitchangelog/internal/issues/IssueParser.java
Line 72 in e37028a
final String matchedIssue = issueMatcher.group(); |