这里记录一下:
public static void main(String[] args) { // 测试数据 String text = "1 \n" + "Ж \n" + "cs:XXXXXXX \n" + " \n" + " XXXXXXX \n" + "一、cs委托人cscscscscs \n" + "二、cscsc scscscs \n" + "三、scscs \n" + "c\n" + "c \n" + "编号 \n" + "今天天气\n" + "不好 \n" + "使用 cs人 "; // 正则表达试 String patternStr = "(?s)(?<=编号).*?(?=使用)"; Pattern pattern = Pattern.compile(patternStr); Matcher matcher = pattern.matcher(text); if (matcher.find()) { String result = matcher.group().trim(); System.out.println("匹配项的内容为 "+result); } else { System.out.println("未找到匹配项"); } }