Skip to content

Instantly share code, notes, and snippets.

@orsenthil
Created February 9, 2017 22:05
Show Gist options
  • Save orsenthil/eef101e534a4bc5bb3fe61d8df254cae to your computer and use it in GitHub Desktop.
Save orsenthil/eef101e534a4bc5bb3fe61d8df254cae to your computer and use it in GitHub Desktop.
import re
RE_PATTERNS= re.compile(r"^#(\d+)|^Issue\s#(\d+)|^Issue#(\d+)", flags=re.MULTILINE | re.IGNORECASE)
test_messages = [
"""#123""",
"""Issue #123""",
"""Issue#123"""
]
for message in test_messages:
t1, t2, t3 = RE_PATTERNS.match(message).groups()
if t1 is not None:
print RE_PATTERNS.sub(r"prefix-\1", message)
if t2 is not None:
print RE_PATTERNS.sub(r"prefix-\2", message)
if t3 is not None:
print RE_PATTERNS.sub(r"prefix-\3", message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment