- 匹配一个符合条件后返回
preg_match()
- 匹配所有符合条件后返回
preg_match_all()
- 匹配符合条件的进行替代
preg_replace()
//例如
$str = "2016-16-16";
$pn = "/(/d*)-(/d*)-(/d*)/";
$re = $1年$2月$3日;
preg_replace($pn,$re,$str);
- 正则匹配(将数组中符合条件的元素形成新数组)
preg_grep()
//例如
$arr = array(
'linux is very much',
'java is very much',
'php is very much',
'python is very much',
);
$arr = preg_preg('/linux|php|java|python/',$arr);
- 正则分割
preg_split()
//例如
$str = "379/738=907+903-5678";
$arr = prep_split('/-|=|\+|\//',$str);