iwato Posted October 13, 2010 Share Posted October 13, 2010 The following code snippet contains a subpattern that I do not understand. I am hoping that someone can explain what it is looking for.The Code Snippet preg_match('@^(?:http://)?([^/]+)@i', "http://www.php.net/index.html", $matches); The Poorly Understood Subpattern: ^(?:http://)?What I understand:The pattern (? followed by certain characters can indicate a variety of different assertions.A pair of colons wrapped around a name indicates the presence of a named character class.As neither of these appear to apply here; however, I am lost as to how to interpret the above subpattern. Can someone help?Roddy Link to comment Share on other sites More sharing options...
mcampbell Posted October 13, 2010 Share Posted October 13, 2010 The Poorly Understood Subpattern: ^(?:http://)? (?: indicates that the subpattern will not be captured. The ^ matches the start of the string, and the ? after the first subpattern indicates that it is optional. The only subpattern captured will be the second, matching "www.php.net". Link to comment Share on other sites More sharing options...
iwato Posted October 13, 2010 Author Share Posted October 13, 2010 (?: indicates that the subpattern will not be captured. (?:Bingo!Many thanks!Roddy Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.