How to find and replace content using python regular expressions
This article mainly introduces how to use python regular expression to find and replace content, the article is very detailed, has a certain reference value, interested friends must read it!
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.
Example
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") # Segmentation mp = p.split ("detect content") above is "how to use" Python regular expressions find and replace all the contents of the article Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!