Python Regular Expression-findall
#coding =utf-8import re ' # Gets the contents of the match ' ' P = re.compile (R ' \d+ ') print ' Find all the numbers ', P.findall (' One1two2three3four4 ') ' # Get matching Content-more complex examples of ' unicodepage = ' <div class= "content" title= "2015-02-22 00:08:46" >i am a boy</div><div class= "content" title= "2015-02-22 00:08:46" >i am a girl</div> ' myMatchStr = Re. FindAll (' <div.*?class= ' content ". *?title=". *? ") >.*?</div> ', Unicodepage,re. S) print ' normal: ', mymatchstr ' get matching content-more complex examples of grouping notation (object array form) ' MyItems = Re.findall (' <div.*?class= "content".) Title= "(. *?)" > (. *?) </div> ', Unicodepage,re. S) print ' Group-object array: ', Myitemsitems = [] "" "" "for item in myitems: print item[0].replace (" \ n "," ") Print item[1].replace ("\ n", "")
Search FindAll Differences
Search finds one and returns at most one match. FindAll can return multiple, match words starting with the first character, search is the full text
Python Regular Expression-findall