In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
What is the use of re.S in Python? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.
Python regular expression
A regular expression is a special sequence of characters that helps you easily check whether a string matches a pattern.
Python has added the re module since version 1.5, which provides Perl-style regular expression patterns.
The re module enables the Python language to have all the regular expression functions.
The compile function generates a regular expression object based on a pattern string and optional flag parameters. The object has a series of methods for regular expression matching and replacement.
The re module also provides functions that are exactly the same as those of these methods, which take a pattern string as their first argument.
This section introduces you to the role of re.S in Python regular expressions, as follows:
In the regular expression of Python, one parameter is re.S. It means "." (excluding outer double quotes, the same below) extends to the entire string, including "\ n". Look at the following code:
Import rea =''asdfsafhellopass: 234455 worldafdsf''b = re.findall ('hello (. *?) world',a) c = re.findall (' hello (. *?) world',a,re.S) print'b is', bprint'c is', c
The running results are as follows:
B is []
C is ['pass:\ n\ t234455\ n\ t']
In regular expressions, "." The purpose of is to match any character except "\ n", that is, it is matched on a single line. The "line" here is distinguished by "\ n". The a string has an "\ n" at the end of each line, but it is not visible.
If the re.S parameter is not used, the match is made only within each line, and if there is no one, the next line starts over and does not cross lines. After using the re.S parameter, the regular expression takes the string as a whole, adds "\ n" as a normal character to the string, and matches it as a whole.
In the introduction to the re.py library, there are the following statements:
"." Matches any character except a newline.
S DOTALL "." Matches any character at all, including the newline.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.