
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to get the number of capture groups in Python regular expression?
The following code gets the number of captured groups using Python regex in given string
Example
import re m = re.match(r"(\d)(\d)(\d)", "632") print len(m.groups())
Output
This gives the output
3
- Related Articles
- Counting the number of groups Java regular expression
- Named capture groups JavaScript Regular Expressions
- How to capture an exception raised by a Python Regular expression?
- How do we use Python Regular Expression named groups?
- How do you access the matched groups in a JavaScript regular expression?
- How to optimize the performance of Python regular expression?
- How to write a Python regular expression to get numbers except decimal?
- How to write Python regular expression to get all the anchor tags in a webpage?
- How to write Python Regular Expression find repeating digits in a number?
- How to extract floating number from text using Python regular expression?
- How to use wildcard in Python regular expression?
- How to use range in Python regular expression?
- How to use variables in Python regular expression?
- How to match parentheses in Python regular expression?
- Regex - reusing patterns to capture groups in JavaScript?

Advertisements