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://)?([^/]+)
thanks in advance
Php regex help
Moderator: General Moderators
- ridgerunner
- Forum Contributor
- Posts: 214
- Joined: Sun Jul 05, 2009 10:39 pm
- Location: SLC, UT
Re: Php regex help
getmizanur wrote: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://)?([^/]+)
thanks in advance
I think the solution they were looking for was this (changing only the firsr regex delim char from / to @):
Code: Select all
preg_match('@^(?:ftp://)?([^/]+)@i');As to what does '(?:ftp://)?([^/]+)' mean? Well, it means:
Optionally match the literal text 'ftp://' and then match one or more non-forward slash characters capturing them into group one.
This is pretty basic stuff. Check out http://www.regular-expressions.info/.