java 正则表达 查找_【已解决】Java的正则表达式Regex中,如何查找所有的匹配的项...

【问题】

java中的正则表达式类是regex,想要去调用,可以查找到,所有的匹配的项。

【解决过程】

1.参考官网:

没有找到相关的。

2.通过NetBeans中,查看find相关的函数,也没有类似于findall之类的函数。

3.网上找了找,找到这个:

然后写出类似的代码:/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package match_digit_and_num;

//http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html

import java.util.regex.Matcher;

import java.util.regex.Pattern;

/**

*

* @author CLi

*/

public class Match_digit_and_num {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

/*

* 如何匹配出类似11A11、22A22、33A33、44B44、55B55这样的字符串,正则表达式怎么写?java中用,跪求各大侠

* http://zhidao.baidu.com/question/507118070.html

*/

String digitNumStr = "11A11、22A22、33A33、44B44、55B55";

//String digitNumStr = "11A11";

Pattern digitNumP = Pattern.compile("(?\\d{2})[A-Z]\\k");

Matcher foundDigitNum = digitNumP.matcher(digitNumStr);

// Find all matches

while (foundDigitNum.find()) {

// Get the matching string

String digitNumList = foundDigitNum.group();

System.out.println(digitNumList);

}

}

}

然后是可以匹配到对应的内容的:11A11

22A22

33A33

44B44

55B55

【总结】

Java中的正则方面的功能,的确还是很弱的。连一次性的获得所有匹配的项,都这么麻烦。

比如C#,Python中麻烦多了。

又一次的验证了那句,Java的正则做的很挫。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值