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: 2983093 |
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 How to create an ordered list that continues numbering from a previous list in HTML
- 2 Conditional Comments in HTML for IE
- 3 What does the server_name directive do?
- 4 How to format HTML in Sublime Text
- 5 How can I use Notepad to compare two text files? (Without external tools, how can this be done manually?)
- 6 Using HTML `textarea` `rows` and `cols`
- 7 Beyond `isset()`: A Deep Dive into Validating and Sanitizing $_POST Arrays
- 8 Flipping the Script: Creative Use Cases for `array_flip` and `array_keys`
- 9 Unpacking Performance: The Truth About PHP Switch vs. if-else
- 10 The Performance Implications of Using `break` in Large-Scale Iterations
- 11 How to properly nest HTML elements
- 12 `break` vs. `continue`: A Definitive Guide to PHP Iteration Control
- 13 Robust Form Processing: Error Handling and User Feedback with $_POST
- 14 How to use the CASE statement in an Oracle query?
- 15 Understanding Sort Stability in PHP: When Relative Order Matters
Latest Tutorials
-
- Go language practical GraphQL
- 3799 2024-04-19
-
- 550W fan master learns JavaScript from scratch step by step
- 5121 2024-04-18
-
- Getting Started with MySQL (Teacher mosh)
- 3195 2024-04-07
-
- Mock.js | Axios.js | Json | Ajax--Ten days of quality class
- 3760 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.

Related recommendations


Popular Recommendations

