PHP正则表达式中的元字符及其例子
<?php
$pattern='/test/';
$str='abctestsdafasfsdfasdtest';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern1='/te\dst/';
$str='te1stdsfsdfsdfdsfds';
var_dump(preg_match_all($pattern1,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern='/te*st/';
$str='abcteeest';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern='/te+st/';
$str='abctest';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern='/te{1}st/';
$str='abctest';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern='/te{3}st/';
$str='abcteeest';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern='/t.{3}st/';
$str='abcteeest';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern='/t.*st/';
$str='abcteeeeest';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern='/t.*st/';
$str='abcteeeeesttestsetestsetst';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern='/1t.*?st/';
$str='1abcteeeees1ttestsetes1tsetst';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern='/1t.*?st/';
$str='1abcteeeees1ttestsetes1tsetst';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern='/^test/';
$str='testabc';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern='/^te.*st$/';
$str='test';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern='/test|abc|AAA/';
$str='testAAAsdfasdfsadfAAAefw';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern='/t[abcde]st/';
$str='tdstAAAsdfasdfsadfAAAefw';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);
echo '<hr>';
$pattern='/t[^e]st/';
$str='tast';
var_dump(preg_match_all($pattern,$str,$arr));
var_dump($arr);