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
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 🙏🙏🙏
I've already tried almost everything, I don't know how to solve it at all.


.*in your restrictive negative lookaheads (e.g.(?!.*__)(?!.*_$)(?!.*_{2,})), so no wonder you do not get expected matches. Restrict the.inside these lookaheads to valid username chars.\w. Here is your regex with\w. Here is BB's regex with\w.