Novice and have a regular problem need to ask!
Novice, when playing the book on the article Publishing tool, with regular matching URL out of a point.
$pattern = '/(http\:\/\/|https\:\/\/)? ([a-za-z0-9-]+\.) + (com|cn|org|net) (\/[\w\%\&\=\ ' \ "\?\/\. *)?/';
$string = ' http://demo.demo.baidu.com ';
Preg_match_all ($pattern, $string, $result);
The result of traversing $result is
[code=php]
Array
(
[0] = = Array
(
[0] = http://demo.demo.baidu.com
)
[1] = = Array
(
[0] =/http
)
[2] = = Array
(
[0] = Baidu.
)
[3] = = Array
(
[0] = = com
)
[4] = = Array
(
[0] = =
)
)
[/php]
The second sub-expression actually matches the ' www. ' and ' Baidu. ', there are two matches, but there is only one match in the returned results t.t
The entire expression is able to match the entire URL, but I want to use the second sub-expression of the two-match results, now only one, I hope you teach the question where to appear!
Thank!
------Solution--------------------
(http\:\/\/
------Solution--------------------
https\:\/\/)? ([a-za-z0-9-]+\.) +) + (com
------Solution--------------------
cn
------Solution--------------------
Org
------Solution--------------------
NET) (\/[\w\%\&\=\ ' \ "\?\/\. *)?
------Solution--------------------
$pattern = '/(http\:\/\/
------Solution--------------------
https\:\/\/)? ((?: [A-za-z0-9-]+\.) +) (COM
------Solution--------------------
cn
------Solution--------------------
Org
------Solution--------------------
NET) (\/[\w%&=\ ' "? \.] *)?/';
$string = ' http://demo.demo.baidu.com ';
Preg_match_all ($pattern, $string, $result);
Array
(
[0] = = Array
(
[0] = http://demo.demo.baidu.com
)
[1] = = Array
(
[0] =/http
)
[2] = = Array
(
[0] = = Demo.demo.baidu.
)
[3] = = Array
(
[0] = = com
)
[4] = = Array
(
)
)