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: 2982832 |
Download: 204 |
Latest Downloads
Red Alert Online
Delta Force
Pokémon UNITE
Fantasy Aquarium
Girls Frontline
Wings of Stars
Little Flower Fairy Fairy Paradise
Restaurant Cute Story
Shanhe Travel Exploration
Love and Producer
24 HoursReading Leaderboard
- 1 How Can I Programmatically Access and Change Non-Inline CSS Values Using JavaScript?
- 2 Mocking with Jest and typescript - a cheatsheet
- 3 Can JavaScript Mimic PHP's Variable Variables?
- 4 Are PHP Global Variables Good or Bad Practice?
- 5 How to Display an Unordered List in Two Columns Across Modern and Legacy Browsers?
- 6 Async Local Storage is Here to Help You
- 7 How Can I Implement Delays in JavaScript Loops to Prevent Overlapping Iterations?
- 8 Can Calling Class Methods with Null Pointers in C Lead to Unexpected Behavior?
- 9 How Can Forward Declarations Solve Circular #include Problems?
- 10 `typename` vs. `class` in C Templates: When Do They Differ?
- 11 Building Composable Platforms with Harmony
- 12 How Can I Effectively Filter Profanity While Avoiding Circumvention Techniques?
- 13 VARCHAR(3000) or TEXT in MySQL: Which is Best for Storing 3000-Character User Messages?
- 14 How Can I Create Corner-Only Borders in CSS?
- 15 What Makes an Object Callable in Object-Oriented Programming?
Latest Tutorials
-
- Go language practical GraphQL
- 2330 2024-04-19
-
- 550W fan master learns JavaScript from scratch step by step
- 3747 2024-04-18
-
- Getting Started with MySQL (Teacher mosh)
- 2000 2024-04-07
-
- Mock.js | Axios.js | Json | Ajax--Ten days of quality class
- 2782 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.