var reg = /.*?(?:\s+(?:OR|AND)\s+|$)/ig; var string = 't.id = 10 OR t.name = "user" AND user.account = 0'; alert(string.match(reg).join('\n'));