python-3.7 - 如何使用 re.sub 替换特定的迭代?
问题描述
我正在为一个项目制作一个 madlibs python 程序,但在替换输入中的特定单词时遇到了麻烦。
我想更改单个迭代,而不是所有迭代。放轻松,我是新手
# Run a loop to replace the words
print("Replacing Words...")
for loopCount in range(replacedNumber):
currentReplace = replaceList[loopCount]
print(re.finditer(r'<.*?>',storyContent))
print("Replacing", currentReplace)
filteredReplaced = re.sub(r'<.*?>',currentReplace, storyContent, loopCount)
注意:仅用于调试的 print() 行
解决方案
推荐阅读
- c++ - 在任何类类型的模板方法中使用 new
- ionic3 - Ionic 3 从子页面的根页面运行功能
- kubernetes - 如何在 Windows 中访问 Kubernetes 集群中的 pod?
- javascript - 如何使用jquery修复div中的多个附加
- angular - Angular 应用程序未在 ie 11 中呈现并给出 SecurityError 和 SyntaxError
- excel - 导出为 PDF 时如何禁用 Excel 工作簿备份创建
- jna - JNA 2 维数组
- windows - 如何在 Windows 中重置/删除使用 setx 设置的环境变量?
- html - 如何将 css 用于图标,以便它能够响应每个文本和每个浏览器分辨率
- codeigniter - 如何在codeigniter中快速将大型csv文件上传到mysql?