Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

368
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda