在python中搜索单个字符串中的字符串
在这段代码中,如何在单个语句中检查单个字符串中的多个字符串在python中搜索单个字符串中的字符串,python,Python,在这段代码中,如何在单个语句中检查单个字符串中的多个字符串 line = '{ AutoLogin = 0; Captive = 0; Closed = 0; Disabled = 0; LastConnected = "2013-11-27 08:38:10 +0000"; Passpoint = 0; PossiblyHiddenNetwork = 0; SPRoaming = 0
line = '{ AutoLogin = 0; Captive = 0; Closed = 0; Disabled = 0; LastConnected = "2013-11-27 08:38:10 +0000"; Passpoint = 0; PossiblyHiddenNetwork = 0; SPRoaming = 0; SSID = <534253>; SSIDString = SBS; SecurityType = "WPA/WPA2 Personal"; SystemMode = 1; TemporarilyDisabled = 0; })'
for token in line.split( ';' ):
if 'RecentNetworks' in token:
start = True
if 'LastConnected' in token:
start = True
line='{AutoLogin=0;Captive=0;Closed=0;Disabled=0;LastConnected=“2013-11-27 08:38:10+0000”;Passpoint=0;PossiblyHiddenNetwork=0;SPRoaming=0;SSID=;SSIDString=SBS;SecurityType=“WPA/WPA2 Personal”;SystemMode=1;暂时禁用=0;})'
对于行中的标记。拆分(“;”):
如果令牌中有“RecentNetworks”:
开始=真
如果令牌中的“LastConnected”:
开始=真
试试这个:
for token in line.split(';'):
start = any(s in token for s in ["RecentNetworks", "LastConnected"])
您可以为此使用正则表达式:
if re.search(r'RecentNetworks|LastConnected', token):
start = True
我不确定这是否比任何
解决方案都快,但我假设它。将是JSON的“行”,在这种情况下,可能更容易将字符串解析为JSON。