Linux學習之Regex

來源:互聯網
上載者:User


Linux學習之Regex Regex字串表示方式一朝不同的嚴謹程度分為基礎Regex和擴充Regex,下面我們來先看看基礎Regex:經常用到的一些符號 [;alnum:]  表示0-9  a-z   A-Z[:alpha:]  表示a-z  A-Z[:lower:] 表示a-z[:upper:] 表示A-Z[:digit:] 表示0-9   www.2cto.com  在學習Regex之前有必要好好瞭解grep的使用 grep [-A] [-B] [--color=auto] '尋找字串' filenameA  後面可以接數字,為after的意思,除了列出該行外,後續的n行業列出來B 後面可以加數字,為before的意思,除了列出改行外,前面的n行業列出來  現在給一段練習Regex的英文段:"Open Source" is a good mechanism to develop programs.apple is my favorite food.Football game is not use feet only.this dress doesn't fit me.However, this dress is about $ 3183 dollars.^MGNU is free air not free beer.^MHer hair is very beauty.^MI can't finish the test.^MOh! The soup taste good.^Mmotorcycle is cheap than car.This window is clear.the symbol '*' is represented as start.Oh!     My god!  www.2cto.com  The gd software is a library for drafting programs.^MYou are the best is mean you are the no. 1.The world <Happy> is the same with "glad".I like dog.google is the best tools for search keyword.goooooogle yes!go! go! Let's go.# I am VBird(從鳥哥私房菜下載)這個檔案共有22行,最下面一行為空白行,現在開始一個案例一個案例的學習吧 案例1 尋找含有the的行

 案例2尋找不含有the的行
 案例3 包含'the' 或者'The'的行
 案例4 尋找包含test,taste的行,仔細分析要求,test,taste中都包含t s,t  www.2cto.com   案例5  找出oo前面不是g的行
 案例6  尋找包含數位行
 案例7  尋找以小寫字母開頭的行

 案例8 找出行尾結束為小數點的 
 案例10 尋找空白行  在正在運算式中 .   表示一個任意的字元* 表示前一個字元有重複0或者多次那麼.*就表示任一字元重複任意多次包括0次 講解最後一個知識點  限定連續字元範圍{}案例11 尋找有2-5個連續0的行  www.2cto.com   
  基礎Regex字元 ^word:  待查字串在行首wrod$  待查字串在行尾* 重複0到無窮多個前一個字元[list] 從字元集和裡面找到想要的字元[^list] 從集合的字元裡面找出不要的字串範圍\{m,n\} 連續m 到n個前一個字元  作者 yuanzeyao2008

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.