Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

372
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!