I need to fetch "repo-name" which is "sonar-repo" from the above multi-line commit string. Can this be achieved with regex? Output Expected: sonar-repo
Here is the string which I need to read using regex,
commit_message=
"""repo-name=sonar-repo;repo-title=Sonar;repo-description=A little demo;repo-requester=Jack
"""
CodePudding user response:
You should be able to use regex to look for repo-name=
and then look for the ;
right after and get what's inbetween. Something like this:
(?<=repo-name=).*?(?=;)
Tested it here with regex101
CodePudding user response:
Try this:
import re
commit_message= 'repo-name=sonar-repo;repo-title=Sonar;repo-description=A little demo;repo-requester=Jack'
print(re.search(r'repo-name=(.*?);', commit_message).group(1))
Output:
sonar-repo