Java相当于JavaScript的String.match()

9 javascript java regex

什么是Java的Java等价物 String.match()

我需要得到一个数组或所有匹配的列表

例:

var str = 'The quick brown fox jumps over the lazy dog';
console.log(str.match(/e/gim));
Run Code Online (Sandbox Code Playgroud)

["e", "e", "e"]
Run Code Online (Sandbox Code Playgroud)

http://www.w3schools.com/jsref/jsref_match.asp

Mac*_*rse 15

检查Regex教程

您的代码应该与此类似:

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));
}
Run Code Online (Sandbox Code Playgroud)