Home >Backend Development >Python Tutorial >What is the python re.compile function?

What is the python re.compile function?

乌拉乌拉~
乌拉乌拉~Original
2018-08-20 17:57:1210063browse

In this article, let’s learn about python re.compile . Some friends may have just come into contact with the python programming language and do not have a special understanding of this aspect, but It doesn't matter. The next article will take you to learn about the compile function in python.

re.compile function

The compile function is used to compile regular expressions and generate a regular expression (Pattern) object for match() and search(). Two functions are used.

The syntax format is as follows:

re.compile(pattern[, flags])

Parameters:

pattern: a regular expression in the form of a string

flags: available Select, indicating matching mode, such as ignoring case, multi-line mode, etc. The specific parameters are:

re.I Ignoring case

re.L Representing special character set \w, \W , \b, \B, \s, \S depends on the current environment

re.M Multi-line mode

re.S is . and any character including newline ( . Excluding newlines)

re.U represents the special character set \w, \W, \b, \B, \d, \D, \s, \S and depends on the Unicode character attribute database

re. A Match object, where:

1.group([group1, …]) method is used to obtain one or more group matching strings. When you want to obtain the entire matching substring, you can use group directly. () or group(0); 2.start([group]) method is used to obtain the starting position of the group matching substring in the entire string (the index of the first character of the substring) , the default value of the parameter is 0; the

3.end([group]) method is used to obtain the end position of the grouped matching substring in the entire string (index 1 of the last character of the substring), parameters The default value is 0;

4.span([group]) method returns (start(group), end(group)).

The above is all the content described in this article. This article mainly introduces the relevant knowledge of the re.compile

function 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 python re.compile function?. 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