In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly talks about "what are the contents of finding and replacing python regular expressions". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the contents of finding and replacing python regular expressions?"
1. Write the Python regular expression string s.
2. Use re.compile to compile regular expressions into regular object Patternp.
3. Regular object p calls p.search or p.findall or p.finditer to find content.
4. Regular object p calls p.sub or p.subn to replace content.
Instance import re s = "regular expression" p = re.compile (s) # find mf1 = p.search ("detect content") mf2 = p.findall ("detect content") mf3 = p.finditer ("detect content") # replace ms = p.sub ("detect content") ms2 = p.subn ("detect content") # split mp = p.split ("detect content")
Content extension:
Common rules for regular expressions
^ matches the beginning of a string, specifying what the string must begin with
$matches the end of the string, specifying that the string ends with the character before $
+ match the previous character one or more times > = 1
{m} specify the number of matching characters
? Match the previous characters 0 or 1 times
Regular expressions are handled by the re module in python. The common methods of the re module are as follows:
Re.match (re rules, strings, modifiers): match from scratch. The match starts with the first character of the string, and if the first character does not match the rule, the match fails.
Re.search (re rules, strings, modifiers): match contains. Matching from the first character of the string is not required. As long as there is a match in the string that matches the rule, the match is successful.
Re.findall (re rules, strings, modifiers): put all matching characters in the list and return.
Re.sub (re rule, replacement string, replaced string, number of substitutions, modifier): match characters and replace.
At this point, I believe you have a deeper understanding of "what are the contents of finding and replacing python regular expressions?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.