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("\.");
  • 相关阅读:
    操作系统第一天学习
    进制之间的转换
    git的使用
    Python 第二天学习(文件的处理)
    下载博客首页的博客列表
    获取所有的列表
    抓取指定博客的内容
    进程简介
    python 内置函数range和xrange
    关于read的例子和条件测试
  • 原文地址:https://www.cnblogs.com/DennyZhao/p/7285747.html
Copyright © 2011-2022 走看看