How can regular expressions like preg_split() and preg_match_all() be utilized in PHP to parse search queries effectively?

Regular expressions like preg_split() and preg_match_all() can be utilized in PHP to effectively parse search queries by allowing you to define specific patterns to match and extract relevant information from the input string. By using these functions, you can easily break down search queries into individual keywords or extract specific data based on predefined patterns.

$search_query = "apple OR banana AND (orange NOT pear)";
$keywords = preg_split('/\s+/', $search_query, -1, PREG_SPLIT_NO_EMPTY);
$operators = preg_split('/\w+/', $search_query, -1, PREG_SPLIT_NO_EMPTY);

print_r($keywords);
print_r($operators);