JHarley
JHarley

Reputation: 11

Output the results of an RE

I have the following code:

import re

targetFile = open("test.txt").read()

print(re.search('(<\\/nesting_tag>)',targetFile))

The idea is I return everything between the . E.g. "Test" when Test. How can I return "Test" as opposed to <_sre.SRE_Match object; span=(56, 70), match=''>?

Upvotes: 1

Views: 38

Answers (1)

Stephen Lin
Stephen Lin

Reputation: 4912

try this

print(re.search('(<\\/nesting_tag>)',targetFile).group())

Upvotes: 1

Related Questions