Upgrade to Pro — share decks privately, control downloads, hide ads and more …

introduction to Regular Expression

CCN
May 13, 2013

introduction to Regular Expression

2013/5/13 in STUST CSIE

CCN

May 13, 2013
Tweet

Other Decks in Programming

Transcript

  1. 移除 HTML Tag ‧全校活動⼀一覽表 ‧南臺校訊 ‧圖書館 ! ! ‧藝⽂文中⼼心 ‧UCAN職能診斷平台

    ‧南臺專利技轉、讓與公告 ! ! ‧本校⽤用電資料 ‧海外留學資訊 ‧雲嘉南區域教學資源中⼼心 ! ! ‧註冊選課專區 ‧推廣教育招⽣生 ‧南臺志⼯工⼤大學 ! ! ‧南臺幼稚園 ‧考選部 ‧南臺Facebook粉絲團 ! ! ‧社團活動專區 ‧性別平等教育委員會 ‧南臺科⼤大夏令營
  2. 移除空⽩白⾏行 • s/^\s*$// ‧全校活動⼀一覽表 ‧南臺校訊 ‧圖書館 ‧藝⽂文中⼼心 ‧UCAN職能診斷平台 ‧南臺專利技轉、讓與公告 ‧本校⽤用電資料

    ‧海外留學資訊 ‧雲嘉南區域教學資源中⼼心 ‧註冊選課專區 ‧推廣教育招⽣生 ‧南臺志⼯工⼤大學 ‧南臺幼稚園 ‧考選部 ‧南臺Facebook粉絲團 ‧社團活動專區 ‧性別平等教育委員會 ‧南臺科⼤大夏令營
  3. Character sequence • /foo/ - match foo • /bar/ -

    match bar • . - wildcard (萬⽤用字元)
  4. Character class • denoted by [] • any character sequence

    • [abc], [AaBbCc], [012345] • character range • [0-9], [A-Z], [0-9A-Z] • mix • [ABC0-5], [A-F0-9]
  5. Character class • Inverse denoted by [^] • inverse sequence

    • [^abc], [^AaBbCc], [^012345] • inverse range • [^0-9], [^A-Z], [^0-9A-Z]
  6. Character class • example • /m[ao]de/ • match - made

    or mode • /[Ss]tust/ • match - Stust or stust
  7. + • match 1+ times • /a+b/ • match ab

    • match aab • match aaab • not match b
  8. * • match 0+ times • /a*b/ • match ab

    • match aab • match aaab • also match b
  9. {n, m} • match least n time but no more

    than m times • /a{2, 3}b/ • match aab • match aaab • not match ab • not match aaaab
  10. {n} • match n time • /a{2}b/ • match aab

    • not match ab • not match aaab
  11. ^ && $ • ⾏行尾 (ending of line) • ^[A-Z][12]\d{8}$

    • A123456789 • AA123456789 • A1234567890
  12. QA