IPアドレスにマッチ
$pattern = '/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/';
$subject = '255.255.255.255';
preg_match($pattern, $subject, $m);
//返り値は 1 $m[0]は 255.255.255.255
//または
$pattern = '/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/';
$subject = '2555.2555.2555.2555';
preg_match($pattern, $subject, $m);
//返り値は 0
ファイル名にマッチ
$pattern = '/[\/a-zA-Z0-9\-]+/';
$subject = '/contents/img/';
preg_match($pattern, $subject, $m);
//$m[0]は /contents/img/
先読み
$pattern = '/Captain(?= America)/';
$subject = 'Captain America';
preg_match($pattern, $subject, $m);
//$m[0]は Captain