Anyone who wants to learn python regular expressions needs to know. 1. match () starts matching from the starting position
2. search () matches any position. if multiple matches exist, only the first matches are returned.
3. finditer () returns all matches
4. every matching is the best matching possible. For example:
>>> M = re. compile ('ABC [bcd] * B ')
>>> M. findall ('abcbcbcb ')
['Abcbcbcb ']
In fact, abcbcb is also the matching abc [bcd] * B, but only returns the maximum matching value.
5. split () method
A. You can specify the maximum number of splits based on the regular expression.
>>> P = re. compile (r' \ W + ')
>>> P. split ('This is a test, short and sweet, of split ().')
['Age', 'is ', 'A', 'test', 'short ', 'and', 'sweet', 'of ', 'Split', '']
B. sometimes, you are not only interested in the texts between delimiters, but also need to know what delimiters are.
If the capturing parentheses are used in RE, their values are also returned as part of the list. Compare the following calls:
>>> P2 = re. compile (r' (\ W + )')
['This', '...', 'Is ', '', 'A','', 'test','. ', '']
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