亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

正則表達式選擇特定的多行

正則表達式選擇特定的多行

LEATH 2021-04-16 18:15:11
我正在嘗試從特定術語后的大量行(最多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之后捕獲行?
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 282 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號