getmizanur Posted May 26, 2010 Share Posted May 26, 2010 elloo, i had a php test today and had to find what was wrong with the following regex preg_match('/^(?:ftp://)?([^/]+)@i'); my answer preg_match('/^(?:ftp:\/\/)?([^/]+@/i'); can anyone tell me if i'm correct or not. and just for understanding, can anyone explain to me what this means (?:ftp://)?([^/]+) Quote Link to comment Share on other sites More sharing options...
cags Posted May 26, 2010 Share Posted May 26, 2010 It's very difficult to say without knowing what it's supposed to match, but are you sure that's the answer you put? Because it is slightly incorrect. You are missing a closing bracket. / - Opening delimiter ^ - Anchor pattern at the start (?:ftp:\/\/)? - A non-capture group to optionally match ftp:// ([^/]+)@ - Capture one or more characters that isn't a forward slash, followed by an @ /i - The ending delimiter and the case-insensitive modifier Quote Link to comment Share on other sites More sharing options...
.josh Posted May 28, 2010 Share Posted May 28, 2010 you're also missing a subject... Quote Link to comment Share on other sites More sharing options...
ZachMEdwards Posted May 29, 2010 Share Posted May 29, 2010 (?:ftp://)?([^/]+) Match the regular expression below «(?:ftp://)?» Between zero and one times, as many times as possible, giving back as needed (greedy) «?» Match the characters “ftp://” literally «ftp://» Match the regular expression below and capture its match into backreference number 1 «([^/]+)» Match any character that is NOT a “/” «[^/]+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.