you may consider to use something like `\s+(AND|OR)($|\s+)` (the main part is to have `\s+`