Skip to content

Use group 1 for Issue matching  #151

@AndreasScharfCPB

Description

@AndreasScharfCPB

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:

final String matchedIssue = issueMatcher.group();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions