Skip to content

Instantly share code, notes, and snippets.

@naranjja
Created April 20, 2018 15:58
Show Gist options
  • Save naranjja/8c4d628e5dd640bdf1e759636912fb9d to your computer and use it in GitHub Desktop.
Save naranjja/8c4d628e5dd640bdf1e759636912fb9d to your computer and use it in GitHub Desktop.
A way to make string replacements upon regular expression matches.
import re
strings = [
'/i wish this were html and not markdown.md',
'/yeah/me/too.md'
]
for s in strings:
print(re.sub(r'\/(.+).md', r'\1.html', s))
# /i wish this were html and not markdown.html
# /yeah/me/too.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment