current location: Home > Download > Learning resources > Web page production > Detailed explanation of python-regular re module

Detailed explanation of python-regular re module
Classify: Learning materials / Web page production | Release time: 2018-01-12 | visits: 2983003 |
Download: 205 |
Latest Downloads
Horror Beat Phase Maker
Himalayan Children
Zebra AI
Supermarket Manager Simulator
Red Alert Online
Delta Force
Pokémon UNITE
Fantasy Aquarium
Girls Frontline
Wings of Stars
24 HoursReading Leaderboard
- 1 What’s 192.168.2.1, Login/Change Password, See the Must-Know
- 2 XML's Advantages in RSS: A Technical Deep Dive
- 3 Oracle's Role in the Business World
- 4 Runescape: Dragonwilds - Temple Woods Vault Guide
- 5 NYT Connections Answers And Hints - April 23, 2025 Solution #682
- 6 Fisch Egg Hunt: Where to find all Easter eggs
- 7 Works 100%: Recover FL Studio Files (Unsaved & Deleted) Easily
- 8 How does cloud computing impact the importance of Java's platform independence?
- 9 What role has Java's platform independence played in its widespread adoption?
- 10 How do containerization technologies (like Docker) affect the importance of Java's platform independence?
- 11 Every Upcoming Release For The Pokemon TCG
- 12 What are the key components of the Java Runtime Environment (JRE)?
- 13 What are the differences in virtualization support between Linux and Windows?
- 14 How does MySQL differ from Oracle?
- 15 What are the disadvantages of using MySQL compared to other relational databases?
Latest Tutorials
-
- Go language practical GraphQL
- 3178 2024-04-19
-
- 550W fan master learns JavaScript from scratch step by step
- 4512 2024-04-18
-
- Getting Started with MySQL (Teacher mosh)
- 2514 2024-04-07
-
- Mock.js | Axios.js | Json | Ajax--Ten days of quality class
- 3222 2024-03-29
The function prototype of re.sub is: re.sub(pattern, repl, string, count)
The second function is the replaced string; in this case it is '-'
The fourth parameter refers to the number of replacements. Defaults to 0, meaning every match is replaced.
re.sub also allows sophisticated handling of replacement of matches using functions. For example: re.sub(r'\s', lambda m: '[' m.group(0) ']', text, 0); Replace the space ' ' in the string with '[ ]'.
re.split
You can use re.split to split a string, such as: re.split(r'\s ', text); split the string into a word list by spaces.
re.findall
re.findall can get all matching strings in the string. For example: re.findall(r'\w*oo\w*', text); Get all words containing 'oo' in the string.
re.compile
Regular expressions can be compiled into a regular expression object. Frequently used regular expressions can be compiled into regular expression objects, which can improve certain efficiency.
