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

    一、正则表达式

       1、正则表达式

           是一个查找、搜索、替换文本的一种格式语言。

       2、导入re模块

           import re               系统自带模块,无需安装

      

       3、模式字符串 == 模子

           

       4、常用方法

            

         4.1  match方法

               match方法是从头开始匹配的,如果匹配不上,那么返回None

               示例

                

    src_str = '{"mobilephone":"${not_existed_tel}","pwd":"123456","regname":"太阳风"}'
    res = re.match(r'{"mobilephone"',src_str)
    # 返回的是一个match对象
    # 建议:使用模式字符串的时候,前面加上一个  r  

       group方法            获取匹配的结果             res.group()

          

        4.2  search方法

              如果能匹配上会返回一个match对象

              匹配不上会返回 None

              search方法只查一次,一旦找到,就不会再继续查找          返回的是一个字符串

             

             示例:

    src_str = '{"mobilephone":"${not_existed_tel}","pwd":"123456","regname":"太阳风"}'
    res1 = re.search(r"${not_existed_tel}",src_str)
    print(res1.group())
    

      

       4.3 findall方法

             查找所有符合条件的。放到一个列表当中

           

           示例

    res2 = re.findall(r"o",src_str)
    print(res2)
    

      

       4.4  sub方法

             替换

               sub第一个参数为模式字符串,第二个参数为新的字符串,第三个参数为原始字符串

            如果能匹配上,那么返回匹配之后的字符串

            如果匹配不上,那么返回原始字符串

           

           示例

          

    res3 = re.sub(r"${not_existed_tel}","18978967865",src_str)
    print(res3)
    

      

    二、ditto工具

       剪切板工具

      

       1、官网

               https://ditto-cp.sourceforge.io/

       2、使用参考

             https://xbeta.info/ditto.htm

          

  • 相关阅读:
    VCL组件之编辑控件
    VCL组件之重要的公用属性
    Delphi Menu Designer(菜单设计器)之三
    Delphi Menu Designer(菜单设计器)之二
    VCL组件之TStrings
    在Google Earth上显示等高线
    [闲聊]恐怖的Google人物头像识别技术
    利用免费的GAE(Google App Engine)建立强大的Blog(micolog)网站
    推荐:Windows live writer 2009(附WIN2003下安装方法)
    Google apps注册以及解析ghs.google.com
  • 原文地址:https://www.cnblogs.com/taiyangfeng/p/12523053.html
Copyright © 2011-2022 走看看