Question: I need some clarification on how regex with the re.findall method works. 

```
pattern = re.compile(r'(?<=\\\\\[-16pt]\n)([\s\S]*?)(?=\\\\\n\\thinhline)')
content= ' '.join(re.findall(pattern, content))

```

So the above prints all the content that the pattern matches with the starting being: `\\[-16pt]` and the ending being '\ \n thinhline' plus all the text after it.
If I had the following content that matched by the pattern:

```
\\[-16pt]
x = 10
print ("hi")
\\
\thinhline
\\[-16pt]
y = 3
print ("bye")
\\
\thinhline
\\[-16pt]
z = 7
print ("zap")
\\
\thinhline
This is random text.
All of this is matched by re.findall, even though it is not included within the pattern.
xyz = "xyz"

```

How would I separate out each group so I could have, for example and be able to edit them independently:

group 1:

```
x = 10
print ("hi")

```

group 2:

```
y = 3
print ("bye")

```

group 3:

```
z = 7
print ("zap")

```

and none of the extra stuff that is matched after it?

Thank you.

Answer: 
```
import re
s=re.findall(r"(?<=\\\\\[-16pt]\n)([\s\S]*?)(?=\\\\\n\\thinhline)",test_str)

```

Findall returns a list of groups matched.

Here `s` is a list.You can access what you want by referring `s[0]` or `s[1]`.
use re.findall

```
pattern=r"""(\\\[-16pt])(\n[a-z]+\s+\={1}\s+[0-9]+)(\nprint\s+\({1}\"[a-z]+\"\){1})\n(\\\nthinhline)\n"""
result=re.findall(pattern,content)
count=1
for item in result:
    print("row",count,item[2])
    count+=1

```

output:

```
row 1 
print ("hi")
row 2 
print ("bye")
row 3 
print ("zap")

```