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

    Join Date
    Jul 2006
    Posts
    22
    Rep Power
    0

    VERY simple match request


    This is so simple (to those who know) I can't find it listed in any library or such.
    I would like to locate (presuming to use preg_match) ... BBcode tag

    [tabstyle number number color]

    I have tried using [[tabstyle-]] - as a range - with various escape attempts for the []
    etc..
    I confess my general lack of regex knowledge and hope someone can help here.

    Thank you.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,056
    Rep Power
    9398
    To escape the []s all you need is a backslash.
    Code:
    \[tabstyle (\d+) (\d+) (something)\]
    If there's something else wrong, what is the input you're testing and what are you trying to get out of it?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2006
    Posts
    22
    Rep Power
    0
    Originally Posted by requinix
    To escape the []s all you need is a backslash.
    I see now - just a matter of being pointed in the right direction.

    Setting the pattern is enough. I was trying to work inside a range (or something )

    Code:
    preg_match("#\[tabstyle (\d+) (\d+) (\w){6}\]#", "$string", $matches)
    where your 'something' will now find 6 character color hex.
    PS.... on further testing I see that matches[3] is only the last character of the 6. I am searching for the (?) that will give me ALL 6. Any thoughts?

    Thank you very much.
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    The complete expression including the quantifier must be enclosed in parantheses: (\w{6})

    It might make sense to add optional spaces between all parts so that the regex won't break when there's e. g. an additional tab between the numbers.
    The 6 worst sins of security How to (properly) access a MySQL database with PHP

    Why cant I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo