zoukankan      html  css  js  c++  java
  • Java正则

    手机号的模糊处理:

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

    替换包括 为“”处理:

                                  test.replaceAll(" | | ", "");

    替换所有包括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);

    将所有不匹配的值全部顶替。

    例:将所有的数据不匹配项转化为. , aa$cc!  ->  aa.cc.
    Pattern pattern = Pattern.compile("[^0-9a-zA-Z.]"); return pattern.matcher(name).replaceAll("\.");
  • 相关阅读:
    linux 终端相关
    「CF10D」LCIS
    「SP1043」GSS1
    「NOI2009」二叉查找树
    「CF650E」Clockwork Bomb
    「UVA10559」Blocks
    「LuoguP3979」遥远的国度
    「SDOI2015」寻宝游戏
    「CF741D」Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
    「CF600E」Lomsat gelral
  • 原文地址:https://www.cnblogs.com/DennyZhao/p/7285747.html
Copyright © 2011-2022 走看看