SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: preg question

  1. #1
    SitePoint Enthusiast microair's Avatar
    Join Date
    Oct 2001
    Location
    My Computer
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preg question

    Hi

    I have little query about preg_match , its basically regular expressions in php
    I want do this...

    search a string for word "user" and also search for a word "admin" which I don't want..

    that is:

    $string ~ user
    &
    $string !~ admin

    in one search...

    if(preg_match ("/(user)/i", $string))

    now how do I put in for the !admin search...

  2. #2
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    REGEX only supports negation for character classes, such as [a-zA-Z].

    In your case.. this can't be utilized. You'll just have to go with a slightly less efficient way:

    if (preg_match("/user/",$string) && !preg_match("/admin/",$string)) {
    /* do stuff */
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •