Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
正規表現について質問です。以下に 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