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
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@]+