import re import sys from typing import Optional pattern = r"^(?:V|v)ersion\ bump(?:ed)?\ to\ ([0-9]+\.[0-9]+\.[0-9]+(?:-[a-zA-Z0-9]+)?).*" def get_commit_message(string) -> Optional[str]: m = re.match(pattern, string) if m: return m.group(1) else: return None if __name__ == "__main__": if len(sys.argv) >= 2: commit_message = sys.argv[1] result = get_commit_message(commit_message) print(result) else: print("Usage: python message.py ")