python - 如何用正则表达式将此形式: (word.Word) 替换为 (word.\nWord)?
问题描述
我想制作一个 Python 代码来检查字符串是否包含类似于以下内容的内容:
'word.Word'
=> 它用'word.\nWord'
.- smallLetter.capitalLetter => smallLeter.\n大写字母。
我发现我应该使用 Python 正则表达式(实际上我不知道如何在其中编写格式!)
我尝试创建此示例:
import re
text = 'What is the.What is thef.How did youDo that?F'
text = re.sub(r"(\.+[A-Z])", r".\n;", text)
输入:'What are you.How did you.When did youDo that?F'
输出:'What are you.\now did you.\nhen did youDo that?F'
我认为它有效,但我不想替换大写字母,我想将其保留在文本中。
例如:输入:'Hey.Wow'
->输出:'Hey.\nWow'
解决方案
推荐阅读
- spring - 发生模板解析错误。(Spring Boot + Thymeleaf)具有布局和静态
- spring - 只接受为生成的 Spring-Server 定义的参数
- java - Java计算字符串中数字、特殊字符和字母的变化次数
- mysql - AUTO_INCREMENT 不受控制的增加
- python - 考虑到数据库的灵活结构和查询,如何在 Django 中使用 mongodb?
- android - 下载模块时出现拆分错误安装
- java - 为什么我在三元运算符中得到 NullPointerException?
- fortran - 之后的意外垃圾?
- angular6 - Popin 在 IE11 中没有关闭
- batch-file - 使用双重延迟扩展在批处理文件中设置变量