1.match () Start match from start position
2.search () matches any position, if there are multiple matches, only the first one is returned.
3.finditer () returns all matches
4. Each match is the best match possible. For example:
>>> m = re.compile (' abc[bcd]*b ')
>>> m.findall (' ABCBCBCB ')
[' ABCBCBCB ']
In fact, ABCBCB is also a matching abc[bcd]*b, but only returns one of the largest matching values.
5.split () method
A. The maximum number of divisions can be specified by dividing the string according to the regular type
>>> p = re.compile (R ' \w+ ')
>>> P.split (' This was a test, short and sweet, of Split (). ')
[' This ', ' was ', ' a ', ' test ', ' short ', ' and ', ' Sweet ', ' of ', ' split ', ']
B. Sometimes, you are not only interested in the text between delimiters, you also need to know what the delimiter is.
If the capture brackets 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