zoukankan      html  css  js  c++  java
  • 正则表达式

    正则表达式:shiyizhong专门用来操作字符串规则,通过一些符号来表示某些程序代码,简化对字符串的复杂操作,但可读性较差。

    常见操作:匹配、获取/查找、切割、替换

    匹配:String类中的matches方法     matches(regex)

    获取(查找):Pattern+Matcher

                         Pattern P=Pattern.compile(regex);          封装规则

                         Matcher m=P.matcher(String);                 关联字符串,获取对应适配器

                         while(m.find())            查找是否包含有指定规则的字符串

                          {

                                      SOP(m.group());                 输出符合规则的内容

                           }

    切割:String中的split()           split(regex)实现复杂切割(连词/叠词)
    替换:replaceAll(regex,str);
    示例:获取连续数字;
               String regex="\d{5,}";           五个以上的连续数字符合规则
               Pattern p=Pattern.compile(regex);
               Matcher m=p.matcher(String);
               while(m.fing())
               {
                            String s=m.group();
                             SOP(s.replaceAll(regex,"#"));'           将符合规则的数据替换掉
                }
     
  • 相关阅读:
    pyftpdlib 搭建FTP服务器
    numpy 解一道简单数学题
    python 实现词云
    个人的毕业长足---- 暴走北京
    Tensorflow of GPU, hello fish by version 0.8.
    图像识别
    用一个Inception v3 架构模型实现简单的迁移学习(译:../tensorflow/tensorflow/examples/image_retraining/retrain.py)
    19.液晶屏的原理
    18.DMA-6410
    17.DMA-2440
  • 原文地址:https://www.cnblogs.com/Strong-stone/p/9699055.html
Copyright © 2011-2022 走看看