I have a string within a tag that I want to extract without finding the tag too. I tried:
string = re.search("\[tag\](.*?)\[tag\]", "[tag]string[tag]")
print(string.group(0))
and
string = re.search("/\[tag\](.*?)\[tag\]/i", "extra[tag]string[tag]extra")
print(string.group(0))
both return
[tag]string[tag]
.group(0)is the entire match. Use.group(1)to get the section in parentheses that you want.