Basics

preg_quote($s1[,$s2]) returns a copy of $s1 with a backslash \ added in front of every character that is part of the regular expression syntax. The special characters are .\+*?[]^$(){}=!<>|:-. If the delimiter $s2 is specified, it will also be escaped.
preg_grep($s,$arr[,$i]) returns an array with entries that match the pattern $s. If $i is set to PREG_GREP_INVERT, the function returns elements that do not match the pattern.
preg_last_error() returns the error code of the last regex execution. The return value can be:
PREG_NO_ERROR
PREG_INTERNAL_ERROR
PREG_BACKTRACK_LIMIT_ERROR
PREG_RECURSION_LIMIT_ERROR
PREG_BAD_UTF8_ERROR
PREG_BAD_UTF8_OFFSET_ERROR

<!DOCTYPE html><html><head></head>
<body><?php

// filtering an array with preg_grep()
$arr=['abc','aab','acd','ade'];
print_r(preg_grep('/ab/',$arr)); echo "<br />";
print_r(preg_grep('/ab/',$arr,PREG_GREP_INVERT));
echo "<br />";

// using other delimiters and the case-insensitive modifier i
print_r(preg_grep('/ab/i',$arr)); echo "<br />";
print_r(preg_grep('|Ab|i',$arr)); echo "<br />";
print_r(preg_grep('+aB+i',$arr)); echo "<br />";
print_r(preg_grep('?AB?i',$arr)); echo "<br />";
print_r(preg_grep('{ab}i',$arr)); echo "<br />";

// using preg_quote()
$word="*very*";
echo preg_quote($word)."<br />";
print_r(preg_grep('/'.preg_quote($word).'/',
                  ['PHP is *very* fun'])); echo "<br />";

// accessing preg_last_error()
switch (preg_last_error()){
   case PREG_NO_ERROR:
      echo "PREG_NO_ERROR";
   break; case PREG_INTERNAL_ERROR:
      echo "PREG_INTERNAL_ERROR";
   break; case PREG_BACKTRACK_LIMIT_ERROR:
      echo "PREG_BACKTRACK_LIMIT_ERROR";
   break; case PREG_RECURSION_LIMIT_ERROR:
      echo "PREG_RECURSION_LIMIT_ERROR";
   break; case PREG_BAD_UTF8_ERROR:
      echo "PREG_BAD_UTF8_ERROR";
   break; case PREG_BAD_UTF8_OFFSET_ERROR:
      echo "PREG_BAD_UTF8_OFFSET_ERROR";
}
?></body></html>

Array ( [0] => abc [1] => aab )
Array ( [2] => acd [3] => ade )
Array ( [0] => abc [1] => aab )
Array ( [0] => abc [1] => aab )
Array ( [0] => abc [1] => aab )
Array ( [0] => abc [1] => aab )
Array ( [0] => abc [1] => aab )
\*very\*
Array ( [0] => PHP is *very* fun )
PREG_NO_ERROR