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: 2982780 |
Download: 204 |
Latest Downloads
Fantasy Aquarium
Girls Frontline
Wings of Stars
Little Flower Fairy Fairy Paradise
Restaurant Cute Story
Shanhe Travel Exploration
Love and Producer
The most powerful brain 3
Odd Dust: Damila
Young Journey to the West 2
24 HoursReading Leaderboard
- 1 Bitcoin (BTC) Price Targets $69K and New All-Time Highs as US Presidential Election Week Begins
- 2 Why Isn't Ellipsis Appearing in My Table Cells?
- 3 dnscbd.dll - What is dnscbd.dll?
- 4 dosbarh.dll - What is dosbarh.dll?
- 5 How to Automate SSH Command Execution with Python Using Paramiko?
- 6 Why Use SwingUtilities.invokeLater?
- 7 SpacePay Presale: A Transformative Opportunity to Acquire SPY Tokens at Unbelievable Prices
- 8 Some of the Largest Cryptocurrency Exchanges Allegedly Ask for Up to Hundreds of Millions of Dollars for New Token Listings
- 9 Mastering Binary Search in JavaScript and Java: A Step-by-Step Guide
- 10 When to Choose Static Classes vs Instantiated Objects in PHP?
- 11 dpserial.dll - What is dpserial.dll?
- 12 MakerDAO Rebranding Confusion Prompts Reconsideration of Sky Strategy
- 13 How to Retrieve the HTML Source of a WebElement in Selenium WebDriver with Python?
- 14 How to Repair Corrupted InnoDB Tables?
- 15 Web3 Conversion Platform Iuppiter Empowers Developers and Reshapes Gaming's Future
Latest Tutorials
-
- Go language practical GraphQL
- 1962 2024-04-19
-
- 550W fan master learns JavaScript from scratch step by step
- 3385 2024-04-18
-
- Getting Started with MySQL (Teacher mosh)
- 1776 2024-04-07
-
- Mock.js | Axios.js | Json | Ajax--Ten days of quality class
- 2593 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.