Issue
I have the following code which matches rdar://problem
(one or more) in the commit_msg, I only want to match it at the beginning of the message, please note that it could be more than one rdar at the beginning of the message, how can I change the regex to do that?
# -*- coding: utf-8 -*-
import re
commit_msg = """
<rdar://problem/19391231> This is the subject line1
<rdar://problem/11121314> This is the subject line2
[Problem]
The Problem description
[Solution]
This is the Solutions section
[Recommended Tests]
This is the Recommended Tests <rdar://problem/12345678> Text
Change-Id: Ibbafa780adb2502d470f12d0280ddb0049c727c4
Reviewed-on: https://tech-gerrit.sd.company.com/17954
Tested-by: Username1 <[email protected]>
Build-watchOS: service account <[email protected]>
Reviewed-by: username2 <[email protected]>
"""
m = re.findall("(?!.*(?:Revert|revert))[\S]*(?:rdar:\/\/problem\/)(\d{8,8})", commit_msg)
print m
CURRENT OUTPUT:-
['19391231', '11121314', '12345678']
EXPECTED OUTPUT:-
['19391231', '11121314']
Solution
Going off your conversation with @ShadowRanger below, how about this?
import re
commit_msg = """
<rdar://problem/19391231> This is the subject line1
<rdar://problem/11121314> This is the subject line2
[Problem]
The Problem description
[Solution]
This is the Solutions section
[Recommended Tests]
This is the Recommended Tests <rdar://problem/12345678> Text
Change-Id: Ibbafa780adb2502d470f12d0280ddb0049c727c4
Reviewed-on: https://tech-gerrit.sd.company.com/17954
Tested-by: Username1 <[email protected]>
Build-watchOS: service account <[email protected]>
Reviewed-by: username2 <[email protected]>
"""
m = re.findall("(?!.*(?:Revert|revert))[\S]*(?:rdar:\/\/problem\/)(\d{8,8})", commit_msg.split('[')[0])
print m
Answered By - robinovitch61
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.