Java equivalent of JavaScript's String.match()

后端 未结 3 569
死守一世寂寞
死守一世寂寞 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

    Check Regex tutorial

    Your code should look something similar to this:

    String input = "The quick brown fox jumps over the lazy dog";
    Matcher matcher = Pattern.compile("e").matcher(input);
    
    while ( matcher.find() ) {
        // Do something with the matched text
        System.out.println(matcher.group(0));
    }
    

提交回复
热议问题