Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the meaning of grouping in python regular expressions

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

I would like to share with you what grouping in python regular expressions means. I believe most people don't know much about it, so share this article for your reference. I hope you will gain a lot after reading this article. Let's learn about it together.

1. By adding parentheses to the regular expression, you can group the matching strings to separate our matching strings.

Multiple sets of left parentheses are numbered from left to right, starting with 1.

2. Grouping simplifies the regular expression and can refer to the grouping itself in the regular expression.

The right side of the grouping can refer to the substrings matched by the grouping by its number. And we can regard the grouping as a whole, and the quantifier can be added after the grouping, and the scope of the quantifier is the whole grouping.

Example

Import rem = "([1-9])\ d *) ([a Murz] {2})" r = re.match (m, "3780qp") if r! = None: print (r.groups ()) # > > ('3780mm,' 3' 'qp') print (r.group (0)) # > > 3780qp print (r.group (1)) # > > 3780 print (r.group (2)) # > > 3 print (r.group (3)) # > > qp#r.group (0) is equivalent to r.group () and above is all the content of the article "what does grouping in python regular expressions mean?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Grouping regular expression article meaning content character string parenthesis quantifier not much function can be passed right most examples that is as a whole more knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MariaDB Shulou Tech Info Linux macOS