pattern.matcher() vs pattern.matches()

前端 未结 8 1919
时光说笑
时光说笑 2020-11-30 06:03

I am wondering why the results of the java regex pattern.matcher() and pattern.matches() differ when provided the same regular expression and same string

         


        
8条回答
  •  没有蜡笔的小新
    2020-11-30 06:03

    pattern.matcher(String s) returns a Matcher that can find patterns in the String s. pattern.matches(String str) tests, if the entire String (str) matches the pattern.

    In brief (just to remember the difference):

    • pattern.matcher - test if the string contains-a pattern
    • pattern.matches - test if the string is-a pattern

提交回复
热议问题