<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ### [組(Groups)](https://lingcoder.gitee.io/onjava8/#/book/18-Strings?id=%e7%bb%84%ef%bc%88groups%ef%bc%89) 組是用括號劃分的正則表達式,可以根據組的編號來引用某個組。組號為 0 表示整個表達式,組號 1 表示被第一對括號括起來的組,以此類推。因此,下面這個表達式, ~~~ A(B(C))D ~~~ 中有三個組:組 0 是`ABCD`,組 1 是`BC`,組 2 是`C`。 `Matcher`對象提供了一系列方法,用以獲取與組相關的信息: * `public int groupCount()`返回該匹配器的模式中的分組數目,組 0 不包括在內。 * `public String group()`返回前一次匹配操作(例如`find()`)的第 0 組(整個匹配)。 * `public String group(int i)`返回前一次匹配操作期間指定的組號,如果匹配成功,但是指定的組沒有匹配輸入字符串的任何部分,則將返回`null`。 * `public int start(int group)`返回在前一次匹配操作中尋找到的組的起始索引。 * `public int end(int group)`返回在前一次匹配操作中尋找到的組的最后一個字符索引加一的值。 下面是正則表達式組的例子: ~~~ // strings/Groups.java import java.util.regex.*; public class Groups { public static final String POEM = "Twas brillig, and the slithy toves\n" + "Did gyre and gimble in the wabe.\n" + "All mimsy were the borogoves,\n" + "And the mome raths outgrabe.\n\n" + "Beware the Jabberwock, my son,\n" + "The jaws that bite, the claws that catch.\n" + "Beware the Jubjub bird, and shun\n" + "The frumious Bandersnatch."; public static void main(String[] args) { Matcher m = Pattern.compile( "(?m)(\\S+)\\s+((\\S+)\\s+(\\S+))$") .matcher(POEM); while(m.find()) { for(int j = 0; j <= m.groupCount(); j++) System.out.print("[" + m.group(j) + "]"); System.out.println(); } } } /* Output: [the slithy toves][the][slithy toves][slithy][toves] [in the wabe.][in][the wabe.][the][wabe.] [were the borogoves,][were][the borogoves,][the][borogoves,] [mome raths outgrabe.][mome][raths outgrabe.][raths][outgrabe.] [Jabberwock, my son,][Jabberwock,][my son,][my][son,] [claws that catch.][claws][that catch.][that][catch.] [bird, and shun][bird,][and shun][and][shun] [The frumious Bandersnatch.][The][frumious Bandersnatch.][frumious][Bandersnatch.] */ ~~~ 這首詩來自于 Lewis Carroll 所寫的*Through the Looking Glass*中的 “Jabberwocky”。可以看到這個正則表達式模式有許多圓括號分組,由任意數目的非空白符(`\\S+`)及隨后的任意數目的空白符(`\\s+`)所組成。目的是捕獲每行的最后3個詞,每行最后以`\$`結束。不過,在正常情況下是將`\$`與整個輸入序列的末端相匹配。所以我們一定要顯式地告知正則表達式注意輸入序列中的換行符。這可以由序列開頭的模式標記`(?m)`來完成(模式標記馬上就會介紹)。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看