Python Regular Expression-findall

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.