Alex Balgavy

Just some stuff about me.

Here's my dotfiles repository.

Check out my blog.

My keys: PGP, SSH

My crypto wallets (BTC, XMR)


What links here:

Better regex with f-strings and re.VERBOSE

Combine f"{whatever}" with r"""...""" to make something like this:

code = r"""
[A-Z]*H  # prefix
\d+      # digits
[a-z]*   # suffix
"""

multicode = fr"""
(?: \( \s* )?               # maybe open paren and maybe space
{code}                      # one code
(?: \s* \+ \s* {code} )*    # maybe followed by other codes, plus-separated
(?: \s* [\):+] )?           # maybe space and maybe close paren or colon or plus
"""

pattern = fr"""
( {multicode} )             # code (capture)
( .*? )                     # message (capture): everything ...
(?=                         # ... up to (but excluding) ...
    {multicode}             # ... the next code
        (?! [^\w\s] )       # (but not when followed by punctuation)
    | $                     # ... or the end
)
"""

Caveats: