Thread: PHP RegEx

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Posts
    64
    Rep Power
    7

    PHP RegEx


    vBulletin incorrectly handles some characters so I've uploaded my question here:

    http://pastebin.ca/1213427
    Last edited by ::Quick::; September 29th, 2008 at 02:32 AM.
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,757
    Rep Power
    9397
    You haven't described the problem that well.
    Code:
    /^(\[[^\]]+\]\s+)?([a-z0-9]{,20})\s+(\d+)%(.*)\s(\d+)/is
    [edit] And a more descriptive title would be nice too.
    Last edited by requinix; September 29th, 2008 at 10:56 AM. Reason: that first [...] part is optional
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Posts
    64
    Rep Power
    7
    Sorry, I had to go somewhere so I was quickly writing it up.

    Basically I need to extract each item in the string into an array:

    Also the Regular Expression but be versatile so that it can correctly process any of the strings included in the Pastebin.
    Last edited by ::Quick::; September 29th, 2008 at 11:41 PM.
  6. #4
  7. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,757
    Rep Power
    9397
    Apparently it didn't like the {,20} syntax.
    Code:
    /^(\[[^\]]+\]\s+)?([a-z0-9]{0,20})\s+((\d+)\s+)?(\d+)%\s+(\S+)\s*(.*)\s(\d+)/is
    [2] = name, [4] = number, [5] = percentage (without the %), [6] = second name, [7] = extra stuff, [8] = second number.

    Beware character encoding problems.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Posts
    64
    Rep Power
    7
    Sorry, I still can't get it to work in the RegEx tester or in PHP.
  10. #6
  11. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,757
    Rep Power
    9397
    Originally Posted by ::Quick::
    Sorry, I still can't get it to work in the RegEx tester or in PHP.
    Works fine for me. One, two, and three.
    If your PHP isn't working then it's your PHP that's not working.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Posts
    64
    Rep Power
    7
    Ah, never mind. Fixed it.

    php.ini problem.

IMN logo majestic logo threadwatch logo seochat tools logo