1
0
Fork 0
mirror of https://github.com/muerwre/vk-tg-bot.git synced 2025-04-25 15:06:41 +07:00

#2 added buttons

This commit is contained in:
Fedor Katurov 2021-04-29 17:43:47 +07:00
parent 8c17836868
commit a59aae9c6e
4 changed files with 98 additions and 3 deletions

17
src/utils/extract.ts Normal file
View file

@ -0,0 +1,17 @@
import { URL } from "url";
const urlRe = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gim;
export const extractURLs = (text: string): URL[] => {
const matches = text.match(urlRe) || [];
return matches
.map((m) => {
try {
return new URL(m);
} catch (e) {
return;
}
})
.filter((el) => el);
};