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

What is the findall function in python regular expressions?

乌拉乌拉~
Release: 2018-08-20 18:04:27
Original
14523 people have browsed it

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]])
Copy after login

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)
Copy after login

Output result:

['123', '456']
['88', '12']
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template