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("\.");
  • 相关阅读:
    PSR
    php类与对象
    二进制、位运算及其用处
    安装LNMP笔记
    计算机基础
    Python3编写HFS(CVE2014-6287)检测脚本
    windows和iis对应版本关系
    phpStudy8.1.0.1配置子域名多网站
    Xml外部实体注入
    xss小游戏通关-全答案
  • 原文地址:https://www.cnblogs.com/DennyZhao/p/7285747.html
Copyright © 2011-2022 走看看