Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8516139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:20:26+00:00 2026-06-11T05:20:26+00:00

Possible Duplicate: How to replace plain URLs with links? I am looking to make

  • 0

Possible Duplicate:
How to replace plain URLs with links?

I am looking to make the user’s life a little easier by parsing text input (via javascript) to find all URLs, then link them (wrap tags) so users can just click them. Facebook and even SO does something similar to give you an idea of what I’m looking for.

function censorLinks(text) {
    return text.replace(
        new RegExp('(https?://[^\\s]+)', 'g'),
        '<a href="$1" target="_blank">$1</a>'
    );
}

I don’t need to support every protocol. I think http and https is find for now. I’m assuming everything beyond http:// up to the white space is a URL. This almost works but there is one tiny problem: if the URL ends with a period, the period gets included. I suppose it is a valid URL but I think it is unlikely in my situation. How can I prevent the period?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:20:28+00:00Added an answer on June 11, 2026 at 5:20 am

    Like @Truth said, this may be a duplicate post but…

    I was recently doing something similar, haven’t tested this but maybe this’ll wrok…

        var email = /(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
        var url = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
    
        function convert(input) {
            return input
                .replace(url,'<a href="$1" target="blank">$1</a>')
                .replace(email, '<a href="mailto:$1">$1</a>');
        }
    

    Edit: fixed typo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to replace plain URLs with links? So I've got a page
Possible Duplicate: jQuery change input type How to replace input[type=submit] to input[type=text] using jQuery?
Possible Duplicate: Make iPhone app paid version replace free version on install from app
Possible Duplicate: Editing a text file in place through C# I need to replace
Possible Duplicate: Eclipse Replace text in all Classes? I want to replace all instances
Possible Duplicate: Is it valid to replace with // in a <script src=“…”>? Links
Possible Duplicate: How to replace image links with img src url in Greasemonkey I'm
Possible Duplicate: Replace individual list elements in Haskell? I have managed to make some
Possible Duplicate: Find and Replace Inside a Text File from a Bash Command I've
Possible Duplicate: Is there an alternative to string.Replace that is case-insensitive? I'm looking for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.