Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use grouping in python regular expressions

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to use grouping in python regular expressions. I hope you will get something after reading this article. Let's discuss it together.

1. Grouping is a string as a whole quantifier, putting the whole string in a pair of parentheses.

2. Grouping regular expressions does not require the use of quantifiers in a string as a whole, and existing groupings can also be referenced in regular expressions.

Example

Import re p = r'(121) {2}'m = re.search (p, '121121abcabc') print (m) print (m.group ()) # returns the matching string print (m.group (1)) # returns the first set of content p = r'(\ d {3pm 4})-(\ d {7pm 8}) m = re.search (p '010-87654321') print (m) print (m.group ()) # returns the matching string print (m.groups ()) # to get all the group content after reading this article I believe you have a certain understanding of "how to use grouping in python regular expressions". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report