Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use grouping in python regular expressions

Shulou Source: shulou.com Published: 2022-06-03 17:36:08 10月15日 Update

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!

Tags: Grouping characters strings regular expressions content whole articles quantifiers done examples parentheses more knowledge industry information information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB vpn Shulou Tech Info Xiaomi Microsoft