I want to have a regular expression that finds the texts that are “wrapped” in between “HEAD or HEADa” and “HEAD. That is, I may have a text that starts with the first word as HEAD or HEADa and the following “heads” are of type HEAD.
HEADnn text...text...HEAD nn text....text HEADnn text....text .....
HEADann text...text...HEAD nn text....text HEADnn text....text .....
I want only to capture the text that are in between the “heads” therefore I have a regex with look behind and look ahead expressions looking for my “heads”. I have the following regex:
var = "HEADa", "HEAD" my_pat = re.compile(r"(?<=^b"+var+r"|"+var+r"b) w*ss(.*?)(?=b"+var +r"b)",re.DOTALL|re.MULTILINE)
However, when I try to execute this regex, I am getting an error message saying that I cannot have variable length in the look behind expression. What is wrong with this regex?
Read more here: Source link