zoukankan      html  css  js  c++  java
  • Regular Expression

    It's a very elegant summary of regular expression from The AWK Programming Language.

    1. The regular expression metacharacters are:  

      ^ $ . [ ] | ( ) * + ?

    2. A basic regular expression is one of the following:

    • a nonmetacharacter, such as A, that matches itself.
    • an escape sequence that matches a special symbol: matches a tab.
    • a quoted metacharacter, such as *, that matches the metaqcharacter literally.
    • ^, which matches the beginning of a string.
    • $, which matches the end of a string.
    • ., which matches any single character.
    • a character class: [ABC] matches any of the characters A, B, or C. Character classes may include abbreviations: [A-Za-z] matches any single letter.
    • a complemented character class: [^0-9] matches any character except a digit.

    3. These operators combine regular expressions into larger ones:

    • alternation: A | B matches A or B.
    • concatenation: AB matches A immediately followed by B.
    • closure: A* matches zero or more A's.
    • positive closure: A+ matches one or more A's.
    • zero or one: A? matches the null string or A.
    • parentheses: (r) matches the same strings as r does.

    Regular Expressions
    Expression Matches
    c  the nonmetacharacter c
    c  escape sequence or literal character c
     ^  beginning of string 
     $  end of string
     .  any character
     [$c_1$$c_2$...]  any character in $c_1$$c_2$
     [^$c_1$$c_2$...]  any character not in $c_1$$c_2$
    [$c_1$-$c_2$]   any character in the range beginning with $c_1$ and ending with $c_2$
     [^$c_1$-$c_2$]  any character not in the range $c_1$ to $c_2$
     $r_1$|$r_2$  any string matched by $r_1$ or $r_2$
    ($r_1$)($r_2$)   any string xy where $r_1$ matches x and $r_2$ matches y; parentheses not needed around arguments with no alternations
     (r)*  zero or more consecutive strings matched by r 
     (r)+  one or more consecutive strings matched by r
     (r)?  zero or one string matched by r parentheses not needed around basic regular expressions 
     (r)  any string matched by r
  • 相关阅读:
    在线整数序列百科全书
    非常完整的线性DP及记忆化搜索讲义
    洛谷P2858 奶牛零食 题解 区间DP入门题
    HDU3394 Railway 题解(边双连通分量)
    POJ1144 Network 题解 点双连通分量(求割点数量)
    LibreOJ6279. 数列分块入门 3 题解
    LibreOJ 6278. 数列分块入门 2 题解
    LibreOJ 6277. 数列分块入门 1 题解
    洛谷P1020 导弹拦截 题解 LIS扩展题 Dilworth定理
    CF1272E. Nearest Opposite Parity 题解 广度优先搜索
  • 原文地址:https://www.cnblogs.com/kid551/p/4177854.html
Copyright © 2011-2022 走看看