SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quick Regex hint please

    Hey. I just need one quick info about regular expressions. There is one thing I don't know how to do. Lets see. Please note, this is just an example to simplify my question. So don't suggest other steps to achieve the same result.

    $string1 = "me&1";
    $string2 = "you&2";

    preg_match("/(me|you)&(.*)/",$string1,$match);

    Now I wonder how should I write part in bold font to have the same meaning but to not have that part in the $match result (index 1). So there are to options: to not use brackets or to exclude result. One of these should do the trick, but which one and how? If there would be only one character, an option would be to use [ab], but what in my case when I have words?


    Thanks.

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    preg_match("/(?:me|you)&(.*)/",$string1,$match); 
    Saul

  3. #3
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php_deamon, thanks again for a solution.


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
  •