问题遇到的现象和发生背景
正则匹配的捕获组结果不准确
用代码块功能插入代码,请勿粘贴截图
ReUtil是hutool的工具类
String text = "你吃早餐了吗,没吃,就去学校上学培训英语课,别偷懒";
List<String> result1 = ReUtil.getAllGroups(Pattern.compile("((吃早餐).*(没吃).*((培训|上学|去学校).*))(英语课)"), text);
System.out.println(JSON.toJSONString(result1));
运行结果及报错内容
["吃早餐了吗,没吃,就去学校上学培训英语课","吃早餐了吗,没吃,就去学校上学培训","吃早餐","没吃","培训","培训","英语课"]
我想要达到的结果
把"去学校"和"上学"一起返回
["吃早餐了吗,没吃,就去学校上学培训英语课","吃早餐了吗,没吃,就去学校上学培训","吃早餐","没吃","培训","上学","学校","培训","英语课"]