import re
text = r"""(@harrys OR from:harrys OR to:harrys OR ("harry's" OR harrys) AND (razor OR razors OR shave OR shaving OR shaved OR shaver OR subscription OR razorhead OR razorheads OR buy OR bought OR buying OR boxers OR cover) AND (has:geo OR has:profile_geo) -styles -prince -markle -meghanmarkle)"""
pattern = r'("[^"]*"|\b(?:(?:OR|AND|sample)\b|(?:from|to|has):))|\w+'
print( re.sub(pattern, lambda m: f'"{m.group(1)}"' if m.group(1) else m.group(), text) )