Tartarus

Would you like to react to this message? Create an account in a few clicks or log in to continue.
Tartarus

The Underworld Of Lightly (& Logically) Moderated Discussion & Debate


3 posters

    Finally! Regexp FTW!

    master5o1
    master5o1
    Nymph
    Nymph


    Finally! Regexp FTW! Empty Finally! Regexp FTW!

    Post  master5o1 Thu Apr 02, 2009 5:43 am

    http://5o1.co.cc/

    I finally got this LiveComments script running today [liek omg it so hard] and I also managed to get it so that any url (http|https|ftp|ftps) is auto-linked using the word filters and regexp that the comment script allows.

    Fuck yeah!

    (comment script found at http://gmail.net/ - no relation to Google).
    Goat
    Goat
    Mortal
    Mortal


    Finally! Regexp FTW! Empty Re: Finally! Regexp FTW!

    Post  Goat Thu Apr 02, 2009 5:54 am

    3.404
    master5o1
    master5o1
    Nymph
    Nymph


    Finally! Regexp FTW! Empty Re: Finally! Regexp FTW!

    Post  master5o1 Thu Apr 02, 2009 6:22 am

    SkYLiNeNZ wrote:3.404

    3.403
    canterella
    canterella
    Giant
    Giant


    Finally! Regexp FTW! Empty Re: Finally! Regexp FTW!

    Post  canterella Thu Apr 02, 2009 6:33 am

    Que? Rolling Eyes
    master5o1
    master5o1
    Nymph
    Nymph


    Finally! Regexp FTW! Empty Re: Finally! Regexp FTW!

    Post  master5o1 Thu Apr 02, 2009 7:26 am

    canterella wrote:Que? Rolling Eyes

    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
    BeginLine OneLine TwoLine ThreeLine FourLine Five / Output
    example.comhttp://example.comNo ActionNo ActionNo ActionClickable http://example.com
    www.example.comwww.http://example.comwww.example.comNo Actionhttp://www.example.comClickable http://www.example.com
    http://example.comhttp://http://example.comNo Actionhttp://example.comNo ActionClickable http://example.com
    http://www.example.comhttp://www.http://example.comhttp://www.example.comNo ActionNo ActionClickable 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 Very Happy
    master5o1
    master5o1
    Nymph
    Nymph


    Finally! Regexp FTW! Empty Re: Finally! Regexp FTW!

    Post  master5o1 Thu Apr 02, 2009 7:27 am

    And since it handles any https and http and ftp and ftps url too it's extra awesome.
    Goat
    Goat
    Mortal
    Mortal


    Finally! Regexp FTW! Empty Re: Finally! Regexp FTW!

    Post  Goat Thu Apr 02, 2009 8:09 am

    I prefer Kate Edgar Lvl 4 but mainly shadz
    master5o1
    master5o1
    Nymph
    Nymph


    Finally! Regexp FTW! Empty Re: Finally! Regexp FTW!

    Post  master5o1 Thu Apr 02, 2009 9:36 am

    SkYLiNeNZ wrote:I prefer Kate Edgar Lvl 4 but mainly shadz

    lol dickbutt
    master5o1
    master5o1
    Nymph
    Nymph


    Finally! Regexp FTW! Empty Re: Finally! Regexp FTW!

    Post  master5o1 Fri Apr 03, 2009 1:59 am

    master5o1 wrote:
    SkYLiNeNZ wrote:I prefer Kate Edgar Lvl 4 but mainly shadz

    lol dickbutt

    LVL 4? NO WAI! ME 2!


    OMG ROFL!!! LIEK! I HERD U LIEK CMPUTRS SO I WAS LIEK, YA RLY I LIEK CMPUTRS AND, LIEK, I LIEK, LIEK CMPUTRS, LIEK OMG DO U LIEK CMPUTRS?

    Sponsored content


    Finally! Regexp FTW! Empty Re: Finally! Regexp FTW!

    Post  Sponsored content


      Current date/time is Fri Apr 19, 2024 2:34 pm