我正在尝试从特定术语后的大量行(最多100到130条)中捕获一组行。这是我的代码。String inp = "Welcome!\n" +" Welcome to the Apache ActiveMQ Console of localhost (ID:InternetXXX022-45298-5447895412354475-2:9) \n" +" You can find more information about Apache ActiveMQ on the Apache ActiveMQ Site \n" +" Broker\n" +" Name localhost\n" +" Version 5.13.3\n" +" ID ID:InternetXXX022-45298-5447895412354475-2:9\n" +" Uptime 14 days 14 hours\n" +" Store percent used 19\n" +" Memory percent used 0\n" +" Temp percent used 0\n" + "Queue Views\n" + "Graph\n" + "Topic Views\n" + " \n" + "Subscribers Views\n"; Pattern rgx = Pattern.compile("(?<=Broker)\n((?:.*\n){1,7})", Pattern.DOTALL); Matcher mtch = rgx.matcher(inp); if (mtch.find()) { String result = mtch.group(); System.out.println(result); }我想从上面提到的inp所有行中捕获下面的行。Name localhost\nVersion 5.13.3\nID ID:InternetXXX022-45298-5447895412354475-2:9\nUptime 14 days 14 hours\nStore percent used 19\nMemory percent used 0\nTemp percent used 0\n但是我的代码给了我“经纪人”之后的所有内容。我可以知道这是怎么回事吗?其次,我想理解,?:表示不捕获组,但是为什么我的regex((?:。* \ n))可以在Broker之后捕获行?
添加回答
举报
0/150
提交
取消