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

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    Regex Match string AND not match string


    Someone help me please!

    I need a regular expression that match one string, and not match a second string in one.

    example

    The searchstring may not match the word "s=001" AND must match the word "msisdn="

    I'm stuk on de Regex: ^((?!s=001).)*$

    this search-string should return true:
    /fotos/site29/set3/518.html?msisdn=%2B31&hash=1FCFA5888E

    en this one false:
    /fotos/site29/set3/518.html?msisdn=%2B31&hash=1FCFA5888E&s=001

    Who can help me??
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    57
    Rep Power
    12
    Hi,

    regexes are the wrong approach for this. If I understand you correctly, you want to make sure that certain URL parameters are given and others not.

    The server language you're using (whatever that is) is much better suited for this kind of task. The parameters are probably parsed automatically (in PHP, for example, they're in the $_GET array). So you can do some simple checks directly on the parameters and don't need to write your own home-made URL parser.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by Jacques3
    Hi,

    regexes are the wrong approach for this. If I understand you correctly, you want to make sure that certain URL parameters are given and others not.

    The server language you're using (whatever that is) is much better suited for this kind of task. The parameters are probably parsed automatically (in PHP, for example, they're in the $_GET array). So you can do some simple checks directly on the parameters and don't need to write your own home-made URL parser.
    Thanks for the quick response, but the problem is i have to check it with Regex and it's not an option to script it.
    If it really is impossible, i have to find an other solution..
    But thanks anyway!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    57
    Rep Power
    12
    Originally Posted by denise1985
    Thanks for the quick response, but the problem is i have to check it with Regex and it's not an option to script it.
    Says who? What exactly do you need this for?

    Yes, it's possible with a regex, but that's just ugly and far from a clean solution. And I can hardly think of a context where you actually have to parse and filter URL parameters with a regex.

    Anyway, my idea would be
    Code:
    /^[^\?]*\?(?:(?!s=001)[^&]+&)*?misisdn=[^&]+(?:&(?!s=001)[^&]+)*$/
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by Jacques3
    Says who? What exactly do you need this for?

    Yes, it's possible with a regex, but that's just ugly and far from a clean solution. And I can hardly think of a context where you actually have to parse and filter URL parameters with a regex.

    Anyway, my idea would be
    Code:
    /^[^\?]*\?(?:(?!s=001)[^&]+&)*?misisdn=[^&]+(?:&(?!s=001)[^&]+)*$/
    I think i can use this! thanks

IMN logo majestic logo threadwatch logo seochat tools logo