master5o1 Thu Apr 02, 2009 7:26 am
canterella wrote:Que?
- Code:
(^|\s*)(\w+(\-?\w+)*)(\.\w+(\.\w+)?)(\/.*)? $1http://$2$4$6
www\.http:\/\/ www.
((ht|f)tps?:\/\/)http:\/\/ $1
(^|\w|\s)(www\.) $1http://$2
((ht|f)tps?:\/\/)?(\w+\.)?(\w+(\-?\w+)*)(\.\w+(\.\w+)?)(\/.*)? <a\thref="$1$3$4$6$8">$1$3$4$6$8</a>
This code above is what I figured out to get it to rewrite URLs as clickable links [it disabled HTML, but since the word filter is awesome I can do this]
I will explain each line:
1. Get any url and add http:// to it...Now this is to handle those "example.com" ones, but coincidentally also handles "http://" and "www." by error.
2. Since we [may have] errored a www.example.com URL and made it "www.http://example.com" we need to switch it back to www.example.com
3. Like 2; we also may have http://http:// urls (bad) so we make them good again by removing the redundant http://.
4. replace any www. with http://www. (this is good and doesn't cause errors like in 1)
5. get all elements of that final URL and make it an <a> tag.
Flow chart (textual)
a) example.com => http:
b) www.example.com
c) http://example.com
d) http://www.example.com
Begin | Line One | Line Two | Line Three | Line Four | Line Five / Output |
example.com | http://example.com | No Action | No Action | No Action | Clickable http://example.com |
www.example.com | www.http://example.com | www.example.com | No Action | http://www.example.com | Clickable http://www.example.com |
http://example.com | http://http://example.com | No Action | http://example.com | No Action | Clickable http://example.com |
http://www.example.com | http://www.http://example.com | http://www.example.com | No Action | No Action | Clickable http://www.example.com |
That there is what I figured out. Random code shit is random, I quite like that table I just drew up