<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Java - `String matches()`方法 > 原文: [https://beginnersbook.com/2013/12/java-string-matches-method-example/](https://beginnersbook.com/2013/12/java-string-matches-method-example/) 方法`matches()`檢查`String`是否與指定的[正則表達式](https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#sum)匹配。如果`String`適合指定的正則表達式,則此方法返回`true`,否則返回`false`。以下是該方法的語法: ```java public boolean matches(String regex) ``` 它會拋出[`PatternSyntaxException`](https://docs.oracle.com/javase/7/docs/api/java/util/regex/PatternSyntaxException.html) - 如果指定的正則表達式無效。 ### 示例:`matches()`方法 在這個例子中,我們有一個`String`和三個正則表達式。我們使用`matches()`方法將正則表達式(regex)與輸入`String`進行匹配。 ```java public class MatchesExample{ public static void main(String args[]){ String str = new String("Java String Methods"); System.out.print("Regex: (.*)String(.*) matches string? " ); System.out.println(str.matches("(.*)String(.*)")); System.out.print("Regex: (.*)Strings(.*) matches string? " ); System.out.println(str.matches("(.*)Strings(.*)")); System.out.print("Regex: (.*)Methods matches string? " ); System.out.println(str.matches("(.*)Methods")); } } ``` 輸出: ```java Regex: (.*)String(.*) matches string? true Regex: (.*)Strings(.*) matches string? false Regex: (.*)Methods matches string? true ```
                  <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>

                              哎呀哎呀视频在线观看