mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
17 lines
559 B
TypeScript
17 lines
559 B
TypeScript
export const urlRegex = /(^| )(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,10}(:[0-9]{1,10})?(\/.*)?$/gm
|
|
export const mailRegex = /([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gi;
|
|
|
|
|
|
export function fixUrls(message: string): string {
|
|
|
|
message = message.replace(urlRegex, function (url) {
|
|
let hyperlink = url.replace(' ', '');
|
|
if (!hyperlink.match('^https?:\/\/')) {
|
|
hyperlink = 'https://' + hyperlink;
|
|
}
|
|
return hyperlink
|
|
});
|
|
|
|
|
|
return message;
|
|
} |