$re = '/((\s*\b([a-zA-Z_]*)\b)\s*((\s*=\s*((\'[\w\-_#@,.!@#$%^&*()\s]*\')))|((\s+\bLIKE\b\s+(\'[\w\-_#@,.!@#$%^&*()\s]*\')))|(((\s+\bIN\b\s+\(\'[\w\-_#@,.!@#$%^&*()\s]+\'(, \'[\w\-_#@,.!@#$%^&*()\s]+\')*\)))))((\s*\b(AND|OR)\b\s*)(\s*\b([a-zA-Z_]*)\b)\s*((\s*=\s*((\'[\w\-_#@,.!@#$%^&*()\s]*\')))|((\s+\bLIKE\b\s+(\'[\w\-_#@,.!@#$%^&*()\s]*\')))|(((\s+\bIN\b\s+\(\'[\w\-_#@,.!@#$%^&*()\s]+\'(, \'[\w\-_#@,.!@#$%^&*()\s]+\')*\))))))*)/m';
$str = 'sponsor_type_trial_company = \'Sponsor\' AND
brief_title_trial LIKE \'%heme%\' AND brief_title_trial LIKE \'%basket%\'
outcome_trial_primary_outcome = \'Bladder Cancer\'
AND sponsor_type_trial_company = \'Sponsor\' AND
overall_status_trial IN (\'Recruiting\', \'Enrolling by invitation\') AND trial_status_trial = \'Open\' AND official_title_trial LIKE \'%Japan%\'
overall_status_trial IN (\'Recruiting\', \'Not yet recruiting\', \'Active, not recruiting\') AND biomarker_strategy_trial_biomarker = \'HER2 low\' AND indication_trial_indication = \'Breast Cancer\'
trial_phase_trial=\'Phase 3\' AND stage_trial_indication_stage=\'Stage IV\' AND outcome_acronym_trial_primary_outcome=\'PFS\'';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php