Click to See Complete Forum and Search --> : [RESOLVED] preg_match
vbbit
May 12th, 2007, 07:14 PM
Can anyone explain this little for e about the regular expr.
"/^(http:\/\/info@)?([^\/]+)/i"
I understand the first part, but after the "?" I dont' get it.
cx323
May 12th, 2007, 11:57 PM
match any character that isn't a "/" as many times as possible (greedy)
vbbit
May 13th, 2007, 01:54 AM
I still don't get it, what do you mean. Could you give me an example of a phrase or a URL?
penagate
May 13th, 2007, 03:53 AM
^ 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:
#^(http://info@)?([^/]+)#i
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.