Get the App
SLTechnology News&Howtos  ›  Development  › 

How to find and replace content using python regular expressions

Shulou Source: shulou.com Published: 2022-06-03 07:20:03 11月15日 Update

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!

Tags: Content regularization detection expressions objects articles values interests characters strings examples guys buddies more knowledge industry information channels channels references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB MySQL vpn Shulou Technology