Task Text Capture Groups Capture tom@hogwarts.com tom Success Capture tom.riddle@hogwarts.com tom.riddle Success Capture tom.riddle+regexone@hogwarts.com tom.riddle Success Capture tom@hogwarts.eu.com tom Success Capture potter@hogwarts.com potter Success Capture harry@hogwarts.com harry Success Capture hermione+regexone@hogwarts.com hermione Success
input: ^([\w\.]*)
Problem 4: Matching HTML
選取”<”以及後面的字母 就是tag瞜!
ex. <a or <div
1 2 3 4 5 6
Capture <a>This is a link</a> a Success Capture <a href='https://regexone.com'>Link</a> a Success Capture <div class='test_style'>Test</div> div Success Capture <div>Hello <span>world</span></div> div Success
input: <(\w+)
Problem 5: Matching specific filenames
| and $的活用
選擇jpg or png or gif $(作為結尾)
1 2 3 4 5 6 7 8 9 10
Skip .bash_profile To be completed Skip workspace.doc To be completed Capture img0912.jpg img0912 jpg Success Capture updated_img0912.png updated_img0912 png Success Skip documentation.html To be completed Capture favicon.gif favicon gif Success Skip img0912.jpg.tmp To be completed Skip access.lock
input:(\w+)\.(jpg|png|gif)$
Problem 6: Trimming whitespace from start and end of line
這邊我使用一開始去掉空白之後抓取全部的文字最後抓取串接以(.)結尾的句子
1 2 3 4
Capture The quick brown fox... The quick brown fox... Success Capture jumps over the lazy dog. jumps over the lazy dog. Success
input: ([^\s+](.+)\.)$
Problem 7: Extracting information from a log file
(\w+)( 純文字以及跳脫字元"(“\
[\w.]+): 這段是抓取所有文字以及有(.)加上一個(:)
(\d+))$ 這段是抓取括號以及數字結尾
1 2 3 4 5 6 7 8
Skip W/dalvikvm( 1553): threadid=1: uncaught exception To be completed Skip E/( 1553): FATAL EXCEPTION: main To be completed Skip E/( 1553): java.lang.StringIndexOutOfBoundsException To be completed Capture E/( 1553): at widget.List.makeView(ListView.java:1727) makeView ListView.java 1727 Success Capture E/( 1553): at widget.List.fillDown(ListView.java:652) fillDown ListView.java 652 Success Capture E/( 1553): at widget.List.fillFrom(ListView.java:709) fillFrom ListView.java 709 Success