dein.fr

Latexify a URL with a Regex

Charles-Axel Dein
today-i-learned

Here's how to generate LaTeX URL in a document:

import re

RE_URL = re.compile(
    r"(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))"
)
text = RE_URL.sub(r"\url{\1}", text)