# "http" gets parsed incorrectly in posts

**URL:** <https://meta.discourse.org/t/http-gets-parsed-incorrectly-in-posts/24866>\
**Category:** Bug\
**Created:** [2월 5, 2015, 1:55오후 UTC](https://meta.discourse.org/t/http-gets-parsed-incorrectly-in-posts/24866 "2015-02-05T13:55:17Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![chapel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapel/32/122414_2.png) [@chapel](https://meta.discourse.org/u/chapel)\
**Post date:** [2월 6, 2015, 8:30오전 UTC](https://meta.discourse.org/t/http-gets-parsed-incorrectly-in-posts/24866/14 "2015-02-06T08:30:41Z")

</div>

Okay, through some trial and error and some looking around I found a regex that passes this edge case and seems to be simple enough but strong enough as well.

```regex
/^((?:https?):\/\/(?:-\.)?(?:[^\s\/?\.#-]+\.?)+(?:\/[^\s]*)?)/

```

I tested it live on here by replacing the existing regex with the above one and testing how it handled the example text from the OP.

Looking at what I can change with the existing regex to have the same properties.

Found the source regex for the above here listed under `@imme_emosol`: [In search of the perfect URL validation regex](https://mathiasbynens.be/demo/url-regex)

Edit: I’ve identified the `g` and `m` flags as causing the issue with the current regex.

Should be:

```plaintext
/^((?:https?:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.])(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\([^\s()<>]+\)|[^`!()\[\]{};:'".,<>?«»“”‘’\s]))/

```

Edit 2: Just submitted a pull request to fix this issue.

[https://github.com/discourse/discourse/pull/3175](https://github.com/discourse/discourse/pull/3175)

---

_[View the full topic](https://meta.discourse.org/t/http-gets-parsed-incorrectly-in-posts/24866)._
