bilis_money Posted June 13, 2006 Share Posted June 13, 2006 ok let say i have these codes below;[code]<?php// get host name from URLpreg_match("/^(http:\/\/)?([^\/]+)/i", "http://www.php.net/index.html", $matches);$host = $matches[2];// get last two segments of host namepreg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);echo "domain name is: {$matches[0]}\n";?> [/code]what bothers me is these --> preg_match("/^(http:\/\/)?([^\/]+)/i", "http://www.php.net/index.html", $matches);specially the special characters like back slash, slash, caret, brackets and etc.i really want to know how to use them properly but unfortunately i tried the manual andit is incomplete. it doesn't tackle the details specially the special characters with preg_math();i hope you can give helpful links or advice on where i can study them deeply so that i can understand them.thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/11838-preg_match/ Share on other sites More sharing options...
robos99 Posted June 13, 2006 Share Posted June 13, 2006 Did you try the page in the manual on regex syntax? The page for the preg_match function has very little info on the syntax, but there's a lot of info on the regex syntax page. [a href=\"http://www.php.net/manual/en/reference.pcre.pattern.syntax.php\" target=\"_blank\"]http://www.php.net/manual/en/reference.pcr...tern.syntax.php[/a] Quote Link to comment https://forums.phpfreaks.com/topic/11838-preg_match/#findComment-44862 Share on other sites More sharing options...
redarrow Posted June 13, 2006 Share Posted June 13, 2006 Are you asking what the regular exsperssion format are.format meaning []^{} whateverthere you go as advised from other member.[code]Regular Expression DetailsIntroductionThe syntax and semantics of the regular expressions supported by PCRE are described below. Regular expressions are also described in the Perl documentation and in a number of other books, some of which have copious examples. Jeffrey Friedl's "Mastering Regular Expressions", published by O'Reilly (ISBN 1-56592-257-3), covers them in great detail. The description here is intended as reference documentation. A regular expression is a pattern that is matched against a subject string from left to right. Most characters stand for themselves in a pattern, and match the corresponding characters in the subject. As a trivial example, the pattern The quick brown fox matches a portion of a subject string that is identical to itself. Meta-charactersThe power of regular expressions comes from the ability to include alternatives and repetitions in the pattern. These are encoded in the pattern by the use of meta-characters, which do not stand for themselves but instead are interpreted in some special way. There are two different sets of meta-characters: those that are recognized anywhere in the pattern except within square brackets, and those that are recognized in square brackets. Outside square brackets, the meta-characters are as follows: \general escape character with several uses^assert start of subject (or line, in multiline mode)$assert end of subject (or line, in multiline mode).match any character except newline (by default)[start character class definition]end character class definition|start of alternative branch(start subpattern)end subpattern?extends the meaning of (, also 0 or 1 quantifier, also quantifier minimizer*0 or more quantifier+1 or more quantifier{start min/max quantifier}end min/max quantifierPart of a pattern that is in square brackets is called a "character class". In a character class the only meta-characters are: \general escape character^negate the class, but only if the first character-indicates character range][/code] Quote Link to comment https://forums.phpfreaks.com/topic/11838-preg_match/#findComment-44863 Share on other sites More sharing options...
bilis_money Posted June 13, 2006 Author Share Posted June 13, 2006 thanks Quote Link to comment https://forums.phpfreaks.com/topic/11838-preg_match/#findComment-44864 Share on other sites More sharing options...
effigy Posted June 13, 2006 Share Posted June 13, 2006 The forward slashes have to be escaped because a forward slash is being used as a delimiter. You could choose a different delimiter and leave the slash as is: '%/%' instead of '/\//' Quote Link to comment https://forums.phpfreaks.com/topic/11838-preg_match/#findComment-45084 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.