【发布时间】:2018-10-18 12:22:00
【问题描述】:
如果我不知道单词是什么,我正在尝试找到一种优雅(简单)的方法来将字符串中的子字符串保存为变量,但我确实知道它之前的四个单词是什么.
如果字符串是(“重置 johnny.mnemonic 的密码”),我需要能够在找到子字符串后存储字符串 johnny.mnemonic?但是怎么做呢?
string = " will you reset password for johnny.mnemonic please"
substring = "reset password for"
if string.find(substring) is not -1:
print("i found the substring to request password reset")
#now add the next sub-string to as a variable here, user should be be next string over
else:
print("sorry, no request found.")
【问题讨论】:
-
我不明白你在问什么...请提供示例...
-
添加了示例代码,希望这能更好地解释我想要做什么。我需要在字符串序列中找到以下字符串(或两个)。
标签: python-3.x input substring