URL Link Converter: Turn Raw Text URLs Into Clickable Links

Contents
If you keep wrapping the http and https addresses mixed into long descriptions or chat logs in <a> tags by hand, this is a simple string replacement that one line of regex can automate.
Once you know the rules for finding where a URL starts and ends, and what the target and rel attributes each do, you can trust the resulting HTML and use it as is.
This post lays out those rules and how the attributes behave by showing how the input maps to the output.
Summary ① A URL is recognized as a string that starts with
httporhttpsand ends before a space, line break, angle bracket (<>), or double quote ("). ②target="_blank"opens the link in a new window (new tab), andrel="noopener noreferrer"keeps the newly opened window from taking control of the original page. ③ With truncation on, only the visible text shrinks to 27 characters, while the actual address inhrefstays exactly the same.
When URLs Stay as Text and Aren't Clickable
When you paste text copied from a messenger or notes app into a forum, email body, or internal wiki, an address that starts with http just looks like characters. A browser drawing it as an underlined link in the address bar or in a particular viewer is a different matter from having an actual <a> tag in the HTML source.
For example, if you copy a presentation script with several reference links or a customer support log with URLs spread across multiple lines straight into a web page, you have to wrap every address by hand in <a href="...">.
Two or three links are fine to handle by hand, but when dozens are mixed in, finding and wrapping each one is a hassle.
How to Convert URLs into Links Directly with Regex, Without a Tool
This conversion needs no server or separate program; it's a single regex replace. Any editor with regex support or one short line of code can produce the same result by hand.
The core regex looks like this.
/(https?:\/\/[^\s\r\n<>"]+)/g
This pattern has two parts.
https?:\/\/— finds the point that starts withhttp://orhttps://. Thes?means the s is optional, so it catches both http and https at once.[^\s\r\n<>"]+— appends one or more characters that are not a space, line break, angle bracket (<or>), or double quote ("). The URL is considered finished the moment it hits one of these five characters.
All you need to do is replace the matched string with <a href="matched URL">matched URL</a>. In JavaScript, that's one line.
text.replace(/(https?:\/\/[^\s\r\n<>"]+)/g, '<a href="$1">$1</a>')
To add new-window or security attributes, add them to the replacement string.
text.replace(/(https?:\/\/[^\s\r\n<>"]+)/g, '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>')
target and rel do different jobs.
target="_blank"— opens the link in a new tab (new window) when clicked, instead of the current tab.rel="noopener noreferrer"— keeps the new tab from getting awindow.openerreference to the original page. If that reference stays, the newly opened page can use JavaScript to change the original tab's address.noopenerblocks that route, andnoreferreralso stops referrer information from being sent.
If you copy this regex and replacement logic as is, you can get the same result without a tool. But if you have several URLs mixed in and want to turn the new-window, security, and truncation options on or off by hand each time, you'll need to rewrite the regex and replacement string every time.
Try it with our URL Link Extractor.
It's free and needs no sign-up. The result updates the moment you change the input.

Common Points of Confusion
Turning on truncation does not shorten the link address (href). Only the visible text is cut to 27 characters, with "..." added after it.
The place you actually go when you click is the original URL, unchanged. If you mistake the display text for the href, you may end up thinking you can copy the shortened address.
The class attribute is a name tag for styling how the link looks with CSS.
- If you enter a class value, the resulting
<a>tag getsclass="your-class"exactly as entered. - Use that name as a selector in a stylesheet to set the color, underline, hover effect, and so on separately.
- If you leave class blank, the
<a>tag gets no class attribute at all.
Here's what each option actually adds to the resulting HTML.
| Option | On (checked) | Off (unchecked) |
|---|---|---|
| Open in new window | Adds target="_blank"; opens in a new tab | No attribute; opens in the current tab |
| Security attributes | Adds rel="noopener noreferrer" | No attribute |
| Truncate long URLs | If over 30 characters, shows only 27 characters plus "..." as the visible text (href stays the original) | Shows the full original URL as the visible text |
This regex treats only spaces, line breaks, angle brackets, and quotes as the end of a URL. So in a sentence like "See this post (https://example.com)." the parentheses, period, or comma stuck directly to the end of the URL are included in the link string.
To keep punctuation out of the link, put a space between the URL and the punctuation in the original text.
Summary
- A URL starts with
http://orhttps://and continues until it hits a space, line break,<,>, or". target="_blank"makes the link open in a new tab, whilerel="noopener noreferrer"keeps the new tab from manipulating the original page. They are two attributes with different jobs.- Truncation only shortens the visible text to 27 characters; the actual destination in href stays the original URL.
- If you enter a class value, the resulting
<a>tag gets that value, so you can style it separately with CSS. - Punctuation attached directly after a URL with no space is included in the link string.
It's free and needs no sign-up. The result updates the moment you change the input.
Frequently Asked Questions
If there are multiple URLs in the text, do they all get converted at once?
Yes. The g (global) flag at the end of the regex scans the whole text and replaces every match. It doesn't stop at the first URL; it turns every http and https address in the input into a link.
Will an address like www.example.com with no http also be converted?
No. The regex only matches strings that start with https?://, so addresses without a protocol are excluded. To turn one into a link, add http:// or https:// to the original text.
What's the difference between the preview and the source code?
The preview renders the converted HTML so you can see it, with links underlined or colored and clickable. The source code is the actual HTML text in the form <a href="...">...</a> that produced that result; you can copy it as is and paste it into another document or code.
When I change the input, do I need to click a button to refresh the results?
No. There's no separate convert button. Every change event in the textarea triggers the regex matching and replacement again, so the preview and source code update immediately.
This article was adapted from our Korean original. Read the Korean original