zoukankan      html  css  js  c++  java
  • Regular Expression Basic

    1. Basic Regular Expression  

      a. "^"     matching the head of a line. "^" must be the first character in a regular expression ,else it only a common character.

      b. "$"  matching the end of a line. "$" must be the last character in a regular expression ,else it only a common character.

        Attention: The "^" is only an anchor if it is the first character in a regular expression,else it only a common character.

              The "$" is only an anchor if it is the last character in a regular expression,else it also only a common character.

              If you want match a "^" in the begin of a line or "$" in the end of the line ,you can use the special characters with a backslash ().

          eg:   ^$ , It can match a blank line

        

      c. "."  matching any silger word, except the end-of-line character

      d. "*"  Repeating previous character zero or many times.

          Attention:

             You must remember that modifiers like "*" , "{3,5}" ,"{3,}" and"{3}" only act as modifiers if they follow a common charater set.

          eg:

           *   : Any line contains an asterisk

           *  : Any line contains an asterisk

             ^*  : Any line starting with an asterisk

      e. [...] Specifying a range of characters

          If you want to mathc specific characters,you can use the square brackets to identify the exact characters you are searching for. The pattern that will match any line of text that contains exactly one numer is.

          Attention: The characters "]' and "-" do not have a special meaning if thed directly follow "[".

          eg:

          []      The common character "[]"

          [-0-9]    Any number or "-"

          [^0-9]    Any character other than a number

          [0-9-]    Any number or "-"

          []0-9]    Any number or "]"

          [0-9-z]    Any number, or any character between "9" and "z“

          [0-9-a]]   Any number, or "-" or "a" or "]"

          POSIX

          [:alnum:]  Alphanumeric

          [:cntrl:]    Control character

          [:lower:]   Lower case character

          [:space:]   whitespace

          [:alpha:]  Alphabetic

          [:digit:]   Digit

          [:upper:]   Upper case character

          [:blank:]   whitespace, tabs, etc.

    2. Extended Regular Expression

         a. Repeating previous character minimum and maximum times.

        {3,5}  : Repeating previous character 3,4 or 5 times.

        {3,}    : Repeating previous character 3 or more times.

        {3}   : Repeating previous character only 3 times.

        eg:

           ^A{2,5}B      : Any line starting with 2,3,4 or 5 "A"s followed by a "B" 

           ^A{3,5}    : Any line starting with 3,4 or 4 "A"

           ^A{3}       : Any line starting with 3 "A"

           {3,5}     : Any line contains {3,5}

      b.  + ,  Repeating the privouse character at least one times

      c. ?  , Repeating the privouse character zero or one times.

      d. |    It is meaning or between two regular expression.

        eg:

          ( expressin1  | expression2  | expression3 )

    3 operator priority

        Regular expression operator priority is following:

                

          []

          *, +, ?, {m}, {m,}, {m,n}

          common character

          ^, $

          |  

  • 相关阅读:
    Rust交叉编译Mac编译Linux/Windows平台
    SpringBoot 如何生成接口文档
    Echarts + Python 实现的动态实时大屏范例
    计算机中的0.1+0.2=0.3吗?(无可避免的浮点误差)
    Odin线刷失败的常见错误原因分析及解决方法(转载)
    Odin3 刷机工具刷机教程, BL、AP、CP 与 CSC 是什么意思(转载)
    各种常见USB接口类型
    三星S8+手机,刷机经验
    小米8手机,MIUI由12.5降级到9.5、安卓由10降到8;先ROOT,再安装Magisk、Xposed的步骤
    手机刷机相关,若干名词
  • 原文地址:https://www.cnblogs.com/ordili/p/3996158.html
Copyright © 2011-2022 走看看