zoukankan      html  css  js  c++  java
  • re

    http://www.starming.com/index.php?action=plugin&v=wave&tpl=union&ac=viewgrouppost&gid=73&tid=17981

    martch和search的区别

            Python提供了两种不同的原始操作:match和search。match是从字符串的起点开始做匹配,而search(perl默认)是从字符串做任意匹配

      正则表达式是' ^ '开头时,match与search是相同的。match只有当且仅当被匹配的字符串开头就能匹配 或 从pos参数的位置开始就能匹配 时才会成功

    re.split(pattern, string, maxsplit=0)


    >>> re.split('W+', 'Words, words, words.')
    ['Words', 'words', 'words', '']

    >>> re.split('W+', 'Words, words, words.', 1)
    ['Words', 'words, words.']


    >>> re.split('(W+)', 'Words,      words,       words.')
    ['Words', ',      ', 'words', ',      ', 'words', '.', '']

    如果在字符串的开始或结尾就匹配,返回的list将会以空串开始或结尾。

    >>> re.split('(W+)', '...words, words...')
    ['', '...', 'words', ', ', 'words', '...', '']

    如果字符串不能匹配,将会返回整个字符串的list。

    >>> re.split("a","bbb")
    ['bbb']

    re.findall(pattern, string, flags=0)

    找到 RE 匹配的所有子串,并把它们作为一个列表返回。这个匹配是从左到右有序地返回。如果无匹配,返回空列表。

    >>> re.findall("a","bcdef")
    []

    >>> re.findall(r"d+","12a32bc43jf3")
    ['12', '32', '43', '3']

  • 相关阅读:
    mvc session验证
    mvc登录验证
    PHP中return的用法
    mvc框架类
    php mvc实现比赛列表
    php MySQLDB类
    php header的几种用法
    php isset()与empty()的使用
    jenkins+springboot+svn linux 自动化部署
    基于netty的websocket例子
  • 原文地址:https://www.cnblogs.com/yuluhuang/p/3383583.html
Copyright © 2011-2022 走看看