[英]python regex: search for variable content inside javascript function
I have a javascript string like given below 我有一个如下所示的javascript字符串
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. 我必须获取
__WML_REDUX_INITIAL_STAET__ =
的内容,其内容是json数据,以便我可以进一步解析json。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.