Python重新找到一行中的两个值

时间:2018-01-30 13:13:52

标签: python python-3.x

我有一个字符串。

  the_string=" T1WFuser=sassaa@findthis.com; TFN_FRAMEWORK_ENV=T1WF; TF_Framework_Cookies=TFN_FRAMEWORK_ENV=T1WF&amp;TFN_BRAND=ThisOne&amp;T1WFStylesLocation=ThisStylesDark/en-US&amp;T1Styles=ThisStyles/Styles/&amp;T1Resource=https://www.Thisone.com/CFRResources/3_7_9_18833/&amp;T1Internal=https://www.Thisone.com/T1WFResources/3_7_9_18833/&amp;T1Domain=Thisone.com&amp;T1Version=3.7.9.18833&amp;T1Theme=Black&amp;TWIAFile=twiaThin.js&amp;FSIFile=FsiThin.js&amp;SSIFile=This.Ssi.Thin.js; BIGipServerAMR-SIP-EGN.ThisONE.COM-80=2393298442.20480.0000; Tfsm.PassedOnce=y; ASP.NET_SessionId=wtqzqzfwijolr245vw0xru45</Cookie><Host>Thisone.com</Host><Referer>https://amr.Thisone.com/This_financial_research_web_ui_banker/3_21/Resources/SelectedReports.html</Referer><TE>chunked;q=1.0</TE><User-Agent>Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; InfoPath.3)</User-Agent><True-Client-IP>159.45.22.7</True-Client-IP>"

现在使用re模块我可以找到:

    T1WFuser=sassaa@findthis.com; and <True-Client-IP>159.45.22.7</True-Client-IP> 

在一行中。

1 个答案:

答案 0 :(得分:1)

r = re.search("T1WFuser=([^ ]*);.*<True-Client-IP>([0-9\.]*)<\/True-Client-IP>", the_string)
r.groups() # prints ('sassaa@findthis.com', '159.45.22.7')