如何为此URL类型编写正则表达式



我对正则表达式有疑问。给定的示例URL以下:

example.com/2012/12/4/akfjalj.html

我如何为此类型的URL编写或定义正则表达式?

如果您能为我提供它,那将是一个很好的帮助。

<?php
$url = "http://example.com/2012/3/1/test.html";
$pattern = '/^https?://[a-z]+/[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[a-z]+.html$/';
$ismatch = preg_match($pattern, $url);
echo $ismatch; // 1 if true, 0 if false
?>

引用http://www.regular-expressions.info/php.html

最新更新