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

    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Regex Basic Help


    I am a complete noob when it comes to regex.

    I am trying to grab user ID Value and the current code I am using is :

    Code:
    userid=(?<=userid\:\s)\w*

    The problem I am facing is, it doesnt work always if we have special characters

    For example if the userid : m#jdk&!k6G

    It would only grab m

    Hope my question was clear.
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,124
    Rep Power
    4304
    Welcome to DevShed Forums, Seodude.

    "\w" means word characters, which are a-z, A-Z, 0-9, and underscore ("_"). You could use "\S" which means non-white-space characters.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0
    Thanks sir.Checking in few minutes. Will report back in few minutes
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0
    For some reason not working for me.

    Code:
    userid: m#$9Va$XcJAt
    If I use this regex
    Code:
    userid=(?<=userid\:\s)\w*
    userid=m

    If I use this regex
    Code:
    userid=(?<=userid\:\s)\s*
    userid=nothing

    Appreicate your help
  8. #5
  9. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,124
    Rep Power
    4304
    "\s" is not the same as "\S". They are opposites, actually. I said the latter.

    Code:
    userid=(?<=userid\:\s)\S*
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0
    Perfect!!!!

    Kisses!!!

IMN logo majestic logo threadwatch logo seochat tools logo