Support more patterns when replacing stuff like 'or' (#6201)