Umair Umair - 1 year ago 79
Python Question

Regex not working to get string between 2 strings. Python 27

From this URL view-source:
I want to get string between

var iframeContent =
obj.onloadCallback = onloadCallback;

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

But it does not work. I am not good at regex so please pardon my lack of knowledge.

I even tried
but it does not work.

Answer Source

It looks like you just want that giant encoded string. I believe yours is failing for two reasons. You're not running in DOTALL mode, which means your . won't match across multiple lines, and your regex is failing because of catastrophic backtracking, which can happen when you have a very long variable length match that matches the same characters as the ones following it.

This should get what you want

m ='var iframeContent = \"([^"]+)\"', html_source)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download