public class Test{ //匹配替换掉order by之后的字符串 public static void main(String[] args) { Pattern pattern = Pattern.compile("order\s+by\s+[^,\s]+(\s+asc|\s+desc)?(\s*,\s*[^,\s]+(\s+asc|\s+desc)?)*", 10); System.out.println(pattern.matcher("from dual order by id desc").replaceAll("")); } }