[Python] The regular expression for parsing Telegram usernames stops parsing valid usernames...

Discussão em 'Python' iniciado por Stack, Outubro 1, 2024.

  1. Stack

    Stack Membro Participativo

    Good afternoon, I have one problem here, I have a regexp that extracts the username in Telegram links, starting from a simple "@" to username.t.me links

    [​IMG]

    The problem is that if I enter @aaaa, @jfewewf, both usernames match correctly, but when I enter @aaaa, @jfewewf_, neither username matches, even though the script should match only username @aaaa (because the username on the right side is not valid)

    Here is my regex:

    (?:(?<!\S)@|(?:(?:https?://|)(?:t\.me|telegram\.(?:me|dog))/(?:c/|)|tg://resolve\?domain=)|(?=^(?!.*__)(?!.*_{2,})[a-z][a-z0-9_]{3,31}(?<!_)\.t\.me$))(?P<username>(?!.*__)(?!.*_$)(?!.*_{2,})[a-z][a-z0-9_]{3,31})(?P<subdomain>\.t\.me)?


    You can test it at this link: https://regex101.com/r/JFF1S0/9

    Please help me

    Thanks in advance!

    I've already tried almost everything, I don't know how to solve it at all (ChatGPT also doesn't help at all)

    Continue reading...

Compartilhe esta Página