Java equivalent of JavaScript's String.match()

后端 未结 3 549
死守一世寂寞
死守一世寂寞 2021-01-11 13:56

What is the Java equivalent of JavaScript\'s String.match()

I need to get an array or a list of all matches

Example:

var str = \         


        
3条回答
  •  走了就别回头了
    2021-01-11 14:25

    String.matches(String regex) is a more direct equivalent, but only use it for one-off regexes. If you'll be using it multiple times, stick with Pattern.compile as suggested.

提交回复
热议问题