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

    import re

    m=re.match("abc","abcdef")

    m=re.match("[0-9]","75ab6def")--------7----从头匹配

    m=re.match("[0-9][0-9]","75ab6def")----------75

    m=re.match("[0-9]{0,10}","755625ab6def")----755625:匹配0——10次

    m=re.match("[0-9]{0,10}","755625ab6def")----:匹配10次

    m=re.findall("[0-9]{1,10}","755625ab6def")---print(m)-755625,6:匹配所有数字

    m=re.findall("[a-zA-Z]{0,10}","755625ab6def")--print(m)--ab,def匹配字符

    m=re.findall(".*","755625ab6def")----------.*匹配所有--'755625ab6def',' '

    m=re.findall(".+","755625ab6def")----------.+匹配1个或多个--'755625ab6def'

    m=re.findall("[a-zA-Z]+","755_625~ab@6def")--------'755','625 ','ab','6def'

    m=re.search("d+","75ab46cdef")--------75

    m=re.search("d+","ab46cdef")---46

    m=re.sub("d+","|","ab46cd6ef")---替换-------"ab|cd|ef"

    m=re.sub("d+","|","ab46cd6ef",count=1)---替换前个-------"ab|cd6ef"

    if m:

      print(m.group())

    print(m)

    print(m.group())------------打印匹配的东西

  • 相关阅读:
    Linux环境下安装JDK
    CentOS 7 更改主机名
    Find Pivot Index之Python实现
    MySQL基本操作之数据库基本操作
    Linux环境下安装单实例MySQL 5.7
    基于时间的ACL配置
    动态ACL的配置
    自反ACL
    OSFPv3的配置
    RIPng 配置
  • 原文地址:https://www.cnblogs.com/my334420/p/6403192.html
Copyright © 2011-2022 走看看