Results 1 to 4 of 4

Thread: [RESOLVED] preg_match

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Resolved [RESOLVED] preg_match

    Can anyone explain this little for e about the regular expr.

    PHP Code:
    "/^(http:\/\/info@)?([^\/]+)/i" 
    I understand the first part, but after the "?" I dont' get it.

  2. #2
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    Re: preg_match

    match any character that isn't a "/" as many times as possible (greedy)

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: preg_match

    I still don't get it, what do you mean. Could you give me an example of a phrase or a URL?

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: preg_match

    ^ is the inversion operator;
    \/ is the escaped form of / since the expression uses / as the delimiter;
    [] denotes a character class;
    [^\/] matches any character that is not /
    + means match at least once;
    [^\/]+ means match at least one character that is not /
    The i flag means match case-insensitively.

    You can make it a bit less ugly by changing the delimiter to something else:
    Code:
    #^(http://info@)?([^/]+)#i

Posting Permissions

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



Click Here to Expand Forum to Full Width