简体   繁体   中英

python regex: search for variable content inside javascript function

I have a javascript string like given below

function() {window.__WML_REDUX_INITIAL_STATE__ = {"uuid":null,"isMobile":false,"isBot":false,"isAdsEnabled":true};}

I have to get contents of __WML_REDUX_INITIAL_STAET__ = whose content is json data so that I could parse the json further.

I'm, using following regex pattern

wml_redux_initial_state = re.findall('__WML_REDUX_INITIAL_STATE__ = (.*?);\s*$', redux, re.M)

But this is not working.

I don't know how specific your regex needs to be, but your current one isn't working because of the } after the ; ....this works:

re.search(r'__WML_REDUX_INITIAL_STATE__ = (.*?);}\s*$', redux, re.M)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM