Reputation: 575
I'd like to parse and remove youtrack issue codes embedded anywhere in commit messages.
For those who have never used youtrack, you can specify issue codes in commits as follows:
#<project>-<issue#> <commit msg>
e.g. #PROJ-3 I like to use git and youtrack
or...
e.g. I'm silly #PROJ-3 and like to use git and youtrack
I have the following regex...
$remove_issue_regex = /( |^)#(\w+-\d+):? ? -? ?/
...which I feed into a sub method replacing the substring with an empty string. But it's ugly and might not work if the user formats their messages in a silly way. Does anyone know a more elegant way to do this?
Upvotes: 0
Views: 232
Reputation: 11643
$remove_issue_regex = /#\w+-\d+ (.*)/
will put the commit message after the stamp as the first capture group
Upvotes: 0
Reputation: 174786
Use a lookbehind,
(?<= |^)#(\w+-\d+)(?=: - )?
OR
(?<= |^)#(\w+-\d+)(?:: - )?
Just replace the whole string with the first captured group to get only the <project>-<issue>
format.
Upvotes: 1