dein.fr

Charles-Axel Dein's personal website

Latexify a URL with a Regex


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)