Regular Expression - Posix

1. Character Class

[:alnum:]   // match number
[:alpha:]    // match char
[:lower:]    // match lower case char
[:upper:]   // match upper case char
[:digit:]     // match float
[:xdigit:]   // match 0x number

[:punct:]   // match punctuation
[:blank:]   // match tab and space key
[:space:]  //match blank char
[:cntrl:]     //match control key
[:print:]     //match all the char that can be printed
[:graph:]   //match all the printed char except the space key

1.1 Repeat (wish some strings can be repeated for multiple times)

* : repeat for 0 or more than 0 times
+: repeat at least 1 times
 
ex: [:alnum:]+     // indicate there is at least 1 character

1.2 Count subexpression

{num}   // the number in the '{}' indicate how many time the content can be repeated.
     {3}  repeat 3 times                 {2, 4} repeat 2 to 4 times

1.3 Locate at start or end point

^ : locate at the beginning of the String  ex: ^There   // the String must begin with There
$:  locate at the end of the String           ex: cat$        // the String must end with cat

1.4 Branches (or)

| : indicate one of these choices       ex: com | edu | net  // match 'com' or 'edu' or 'net' for the email

2. Special character

2.1 the special char used outside the bracket    ... [ ]

\ : escape character
^: matching at the beginning of String
$: matching at the end of String
.(dot) : matching the char except '\n'
| : branch (or)
(....) : full match
* : repeat more than 0 times , including 0
+: repeat at least 1 times
{ num } : count how many time the String can be repeated
? : indicate one of the modular is optional

2.2 the special char used inside the bracket    [...]

\ : escape character
^: used at the beginning, indicate 'nor'
- : indicate the 'range'
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章