如果我有一个像 str1 = "IWantToMasterPython"
这样的字符串
如果我想提取 "Py"
从上面的字符串。我写:
extractedString = foo("Master","thon")
我想做这一切,因为我正在尝试从 html 页面中提取歌词。歌词写成<div class = "lyricbox"> ....lyrics goes here....</div>
.
关于如何实现的任何建议。
最佳答案
解决方案是使用正则表达式:
import re
r = re.compile('Master(.*?)thon')
m = r.search(str1)
if m:
lyrics = m.group(1)
关于python - 如何在python中的其他两个字符串之间提取一个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1376640/