• Regular Expression Patterns


    Regular Expression Patterns

    Following lists the regular expression syntax that is available in Python.

    Pattern Description
    ^ match beginning of the line.
    $ match end of line.
    . match any single character except ' '.
    [...] match any single character in brackets.
    re* match 0 or more occurrences of preceding expression
    re+ match 1 or more occurrences of preceding expression
    re? match 0 or 1 occurrence of preceding expression.
    re{n} match exactly n number of occurrences of preceding expression.
    1...9 match n-th grouped sub-expression.
    (re) Groups regular expressions and remembers matched text.

    Examples

    # <
    ESCAPE_RE = r'\(.)'
    
    # *emphasis*
    EMPHASIS_RE = r'(*)([^*]+)2'
    
    # **strong**
    STRONG_RE = r'(*{2}|_{2})(.+?)2'
    
    # ***strongem*** or ***em*strong**
    EM_STRONG_RE = r'(*|_)2{2}(.+?)2(.*?)2{2}'
    
    # ***strong**em*
    STRONG_EM_RE = r'(*|_)2{2}(.+?)2{2}(.*?)2'
    
    # _smart_emphasis_
    SMART_EMPHASIS_RE = r'(?<!w)(_)(?!_)(.+?)(?<!_)2(?!w)'
    
    # _emphasis_
    EMPHASIS_2_RE = r'(_)(.+?)2'
    
    # [text](url) or [text](<url>) or [text](url "title")
    LINK_RE = NOIMG + BRK + 
        r'''(s*(<.*?>|((?:(?:(.*?))|[^()]))*?)s*((['"])(.*?)12s*)?)'''
    
    # ![alttxt](http://x.com/) or ![alttxt](<http://x.com/>)
    IMAGE_LINK_RE = r'!' + BRK + r's*(s*(<.*?>|([^")s]+s*"[^"]*"|[^)s]*))s*)'
    
    # [Google][3]
    REFERENCE_RE = NOIMG + BRK + r's?[([^]]*)]'
    
    # [Google]
    SHORT_REF_RE = NOIMG + r'[([^]]+)]'
    
    
  • 相关阅读:
    Git for Android Studio 学习笔记
    ACM-线段树区间更新+离散化
    hdu 1394 逆序数(线段树)
    Android瀑布流照片
    Android照片墙-多图加载
    Android-加载图片避免OOM
    Android-自定义View实现ImageView播放gif
    maven---工程建立及目录添加--
    oracle--视图(2)---
    Hibernate---Hql查询2---
  • 原文地址:https://www.cnblogs.com/ZJUT-jiangnan/p/6381267.html
Copyright © 2020-2023  润新知