Java正则

手机号的模糊处理:

                              phone.replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2")

替换包括\r\n\t为“”处理:

                              test.replaceAll("\r|\t|\n", "");

替换所有包括aoeiuAOEIU之一 剔除vowel内容:

        str.replaceAll("[aoeiuAOEIU]", "");

判断字符串是否存在:       

1 String reg = ".*/login.*|.*/manual.*";
2 Pattern pattern = Pattern.compile(reg);
3 String test = "/rest/loginMy";
4 System.out.println(pattern.matcher(test).matches()); ---true

 获取重复的字符串:

        String abc = "DDF,ABC,BDF";
        String arr = ".*(ABC|BBE|CCG).*";
        String result = abc.replaceAll(arr, "$1");
      // 另一种 Pattern regexp
= Pattern.compile(arr); Matcher match = regexp.matcher(abc); match.matches(); String result = match.group(1);

 

转载于:https://www.cnblogs.com/DennyZhao/p/7285747.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值