Remove Full URL from a string with JavaScript

Posted by I. B. Gd Pramana A. Putra, 18 Aug 22, last updated 18 Aug 22

Looking for a way to remove a full URL from a string with JavaScript? Let's take a look on how to do it with our quick code snippet:

const url = "Visit this page as a url";
const result = url.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '');

console.log("Removed url result: ", result);

The result:

Visit this page  as a url

I love sharing code snippets as most of the time, a quick code example is what we're looking for instead of long-written articles. If you think my code snippets are helpful and save you a lot of time, please consider buying me a cup of coffee :)

Support me via · paypal · buymeacoffee · ko-fi · trakteer
Contributed Snippets
Answer & Responses
    No comments yet

Wanna write a response?

You have to login before write a comment to this post.