Jump to content

Regular Expressions


iwato

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...