1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

The regex for everything but the character "]"

Discussion in 'PHP' started by Meth_, Feb 14, 2008.

  1. #1
    Anyone got the regex to allow any character but "]"

    ehh

    //quote
    '/\[quote\=([a-zA-Z0-9-_!\.$\+%^ ?]+)](.*?)\[\/quote\]/is' => "<blockquote><div><cite><i>Posted By:</i> \\1</cite>\\2</div></blockquote>",
    
    PHP:
    I'm sick of adding things to the regex when people change their usernames with different characters on my forums

    so yeah

    Idk if this makes sense, so sorry if I'm blabbering on


    buttttttt

    I want

    [ quote=5454fd$%(£"$!%*!%*!"%)¬_*"%% ]dsfgsdf[ /quote ]

    to work

    but not

    [ quote=fdsf]] fsf [ /quote ]
     
    Meth_, Feb 14, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    '/\[quote\=([^]]+)\](.*?)\[\/quote\]/is' => "<blockquote><div><cite><i>Posted By:</i> \\1</cite>\\2</div></blockquote>",
    PHP:
    When using ^ in the square brackets [ ], it means NOT, unlike when using it outside of them means the beginning of the string. So basically, the code to put in your first ( ) is [^]]+

    This will basically mean as long as the next char isn't ], continue, and when it finally does hit one, it will obviously break out of the ( ) and assume the ] is for the closing of the opening quote tag.

    Also, you forgot to escape the closing ] in your first quote tag, which I did in my example. Oddly enough, you do not escape the ] inside the []. At least I didn't have to, and when I did, it did not work properly.

    EDIT: Actually, nevermind, you shouldn't have to escape that closing ] that I said you missed. Doesn't seem to matter. Just gotta escape the opening ones, most likely.

    Let me know how it works! :)
     
    zerxer, Feb 14, 2008 IP
    Meth_ likes this.
  3. Meth_

    Meth_ Well-Known Member

    Messages:
    1,063
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    140
    #3
    hey, thanks a lot!
    that works perfectly, and I've learnt something new :p


    +rep
     
    Meth_, Feb 15, 2008 IP