I have a Python code that parses a text file and finds instances of the words within a tag @(my word)
. To do this I use, e.g.,:
import re
DEF_RE = r"(@\()(?P<text>.+?)\)"
sometext = "find the @(tagged text)."
m = re.search(DEF_RE, sometext)
print(m.group("text"))
tagged text
However, if the file contains the tagged text split over two lines the above method doesn't work, e.g.,
sometext = "find the @(tagged\ntext)."
m = re.search(DEF_RE, sometext)
print(m)
None
Is there are way to change my regular expression string to allow the text to be split over a line?