Java相当于JavaScript的String.match() [英] Java equivalent of JavaScript's String.match()

查看:140
本文介绍了Java相当于JavaScript的String.match()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我需要获取数组或所有匹配项列表

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

示例:

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

给予

["e", "e", "e"]

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

推荐答案

检查 Regex教程

您的代码应该与此类似:

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));
}

这篇关于Java相当于JavaScript的String.match()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆