如何在字符串中找到子字符串的所有实例?
例如,我有字符串("%1 is going to the %2 with %3").我需要提取所有占位符在此字符串(%1,%2,%3)
当前代码只能找到前两个,因为结尾不是空格.
import re
string = "%1 is going to the %2 with %3"
r = re.compile('%(.*?) ')
m = r.finditer(string)
for y in m:
print (y.group())
Run Code Online (Sandbox Code Playgroud) 使用python find函数,我想确定字符串中是否有"="符号.它可以找到其他任何"=".
string: Math="Fun".
if (string.find("=") > -1):
有任何想法吗?