pattern.matcher() vs pattern.matches()

前端 未结 8 1907
时光说笑
时光说笑 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:04

    The code equivalent to java.util.regex.Pattern.matches("\\+", str) would be:

    Pattern.compile("\\+").matcher(str).matches();
    

    method find will find the first occurrence of the pattern in the string.

提交回复
热议问题