> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Use Getitem For Re Match Groups

#### Sourcery refactoring id: `use-getitem-for-re-match-groups`

#### Description

Access groups in
[`re.Match`](https://docs.python.org/3/library/re.html#match-objects) objects
using `getitem`

#### Before

```python
m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
entire = m.group(0)  # The entire match
first = m.group(1)  # The first parenthesized subgroup.
```

#### After

```python
m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
entire = m[0]  # The entire match
first = m[1]  # The first parenthesized subgroup.
```

#### Explanation

In Python 3.6 the ability to access groups from a match using `__getitem__` was
[introduced](https://docs.python.org/3/library/re.html#re.Match.__getitem__).
This is slightly shorter, and once you've understood that it is possible, easier
to read and understand.
