简体   繁体   中英

Python regular expression for commit messages

I am trying to construct a regular expression for commit messages of the following format...

<message> Issue: <issue> [Reviewer: <reviewer>]

As you can see, the reviewer section is optional - not every commit has to be reviewed. However, if the reviewer LABEL has been provided - the actual reviewer person is required.

Here is my regular expression so far

The regex is set up so it captures the message , issue , and reviewer . The problem is, if you don't specify a reviewer - the regex still matches. How can I make it require an actual reviewer rather than just the label "Reviewer"?

EDIT:

Valid examples...

Updated code. Issue: FOO-123.

Updated tests. Issue: BAR-123. Reviewer: Tim

Invalid example...

Updated readme. Issue: AAA-123. Reviewer:

You'll have to be more specific in matching what qualifies as an issue. If anything can qualify as an issue then "FOO-123. Reviewer:" is a valid issue name. If you know your issue will look like "FOO-123" then you can restrict matches to [AZ]+-[0-9]+ Here is an example .

Can you work with something like:

^(.*?)\sIssue:\s(.*?)\sReviewer:\s(.*?)$

Regex Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM