Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

373
Visualizações
delete @ids and text contain link from messages of telegram bot

I have a telegram bot and I want to delete all links from text , but here , I Have two problems :

1.I don't know how to delete all Ids like this : @id with current regex that i have in my code

2.Also I want to delete all strings that have links (in telegram for add link to a text , select text and right click > formatting >create link, then the color of your text will turn blue and your text will become a link)

so this is my current code and delete links from input :

bot.on("text", async function (msg){
  const text = msg.text.replace(
    /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/g,
    ""
  );

  console.log(text);
})

bot.start();

But I want delete ids (everything after @) and the text contain links

also I use TeleBot for using telegram bot

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could add an alternation | matching an @ followed by any char except @ or a whitespace char to your pattern using |\B@[^\s@]+

Note that for a match only you can turn the outer capture group for the first part to a non capture group as you replace the match only with an empty string.

\b(?:(?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|\B@[^\s@]+

See a regex demo

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda