Home >Backend Development >Python Tutorial >What is the findall function in python regular expressions?

What is the findall function in python regular expressions?

乌拉乌拉~
乌拉乌拉~Original
2018-08-20 18:04:2714554browse

In this article, let’s learn about the relevant knowledge about python regular expressions. Some friends may have just come into contact with the python programming language and do not have a special understanding of this aspect. In the next article, we will take you to learn about the python findall function in regular expressions.

Summary

Find all substrings matched by the regular expression in the string and return a list. If no match is found, an empty list is returned.

(Note: match and search match once and findall matches all.)

The syntax format is:

findall(string[, pos[, endpos]])

Parameters

string : The string to be matched.

pos: Optional parameter, specifying the starting position of the string, the default is 0.

endpos: Optional parameter, specifying the end position of the string, defaulting to the length of the string.

For example, find all the numbers in the string:

# -*- coding:UTF8 -*-
 
import re
 
pattern = re.compile(r'\d+')   # 查找数字
result1 = pattern.findall('runoob 123 google 456')
result2 = pattern.findall('run88oob123google456', 0, 10)
 
print(result1)
print(result2)

Output result:

['123', '456']
['88', '12']

The above is all the content of this article, this article mainly introduces I have learned the relevant knowledge about findall in regular expressions in python. I hope you can use the information to understand the above content. I hope what I have described in this article will be helpful to you and make it easier for you to learn python.

For more related knowledge, please visit the

Python tutorial column on the php Chinese website.

The above is the detailed content of What is the findall function in python regular expressions?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more