Regex does not work to get a line between two lines. Python 27

From this url: https://www.amazon.com/dp/073532753X?smid=A3P5ROKL5A1OLE I want to get a line between var iframeContent =andobj.onloadCallback = onloadCallback;

I have this regex iframeContent(.*?)obj.onloadCallback = onloadCallback;

But that will not work. I am not good at regular expression, so please apologize for the lack of knowledge.

I even tried iframeContent(.*?)obj.onloadCallback, but it does not work.

+4
source share
3 answers

, . , . DOTALL, , . , - , , , , , .

,

m = re.search(r'var iframeContent = \"([^"]+)\"', html_source)
print m.group(1)

, [^"], . , , .

+3

, . re.M (.. re.findall('someString', text_Holder, re.M)).

+3

(?<=iframeContent =)(.*)(?=obj.onloadCallback = onloadCallback)

You can check this site in the test.

It is very important to use the mode DOTALL, which means that you will have a single line

+2
source

Source: https://habr.com/ru/post/1658281/


All Articles