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

    Join Date
    Feb 2007
    Posts
    3
    Rep Power
    0

    How to get values a and b in "a[b]"


    Hi, I've never been able to get the hang of regex . Could anybody please help me out? With a string of:

    a[b]

    ...I need to return value a and b. I was going to cheat and use explode() twice but, well that's not very efficient is it.

    thanks all
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    833
    Rep Power
    496
    What are "a" and "b"? Single letters, words, numbers? If you really looking for single letters, then you could use this regex:

    Code:
    /(\w)\[(\w)\]/
    Or, if you can have several letters:

    Code:
    /(\w+)\[(\w+)\]/

IMN logo majestic logo threadwatch logo seochat tools logo