In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to use regular expressions to add, delete, and replace functions, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
#-*-conding:utf-8-*-import retxt = 'the volume of this pool is about 34 cubic meters' role is the matching rule The format of re_out for replacement part is "\ 1 (replacement part)"''def Replace (role,re_out): out = re.compile (role) String_out = out.sub (re_out,txt) print (String_out) Replace (r' (the volume of this pool is about 34) (. *)', r'\ 1 square meter')''role is the matching rule Num is the element to be deleted (starting from 1)''def Delete (role,num): out = re.search (role,txt) .group (num) string = txt.split (out) String_out =' .join (string) print (String_out) Delete ('(the pool is about 34) (. *) (volume)', 2) def Add (role,re_out): out = re.compile (role) String_out = out.sub (re_out) Txt) print (String_out) Add (r'(the volume of this pool is about 34) (. {0})', r'\ 1')
The following picture is the result of the editor running these three functions. You can take a look at it. If you need it, you can refer to it. In addition, the editor needs someone to tell me how to implement this regular expression with automata and what his principle is. Welcome your comments.
The above content is how to use regular expressions to add, delete, and replace functions. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.