Python re module findall function usage Brief

Source: Internet
Author: User

Tag: Relative import contains margin Imp expression regular expression string Tran

Python re module findall function usage Brief code Example:
1>>>Import re2>>> s ="adfad asdfasdf asdfas asdfawef ASD Adsfas"  3   4>>> reObj1 = Re.compile ('((\w+) \s+\w+)')  5>>>Reobj1.findall (s)6[('Adfad asdfasdf','Adfad'), ('Asdfas asdfawef','Asdfas'), ('ASD Adsfas','ASD')]  7   8>>> reObj2 = Re.compile ('(\w+) \s+\w+')  9>>>Reobj2.findall (s)Ten['Adfad','Asdfas','ASD']   One    A>>> reObj3 = Re.compile ('\w+\s+\w+')   ->>>Reobj3.findall (s) -['Adfad asdfasdf','Asdfas asdfawef','ASD Adsfas']
View CodeDetailed:

The FindAll function returns a list of all occurrences of a regular expression in a string, where the "results" in the list are presented, that is, the information contained in the list is returned in FindAll.

@1. When there are multiple parentheses in the given regular expression, the element of the list is the same as the number of strings in the Tuple,tuple, and the string content corresponds to the regular expression in parentheses, and the emission order is in parentheses.

@2. When a given regular expression has a parenthesis, the element of the list is a string, and the contents of the string correspond to the regular expression in parentheses (not the match for the entire regular expression).

@3. When there are no parentheses in the given regular expression, the element of the list is a string that matches the entire regular expression.

original link

Python re module findall function usage Brief

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.