你好,我想将文本文件中的所有“姓氏”实例从全大写替换为正确大小写。DOE 替换为 Doe 或 IPSUM 替换为 Ipsum,如下所示
Name = John DOE
Random info 1
Random info 2
RandomInfo
Name = Lorem IPSUM
Random info 1
Random info 2
RandomInfo
到
Name = John Doe
Random info 1
Random info 2
RandomInfo
Name = Lorem Ipsum
Random info 1
Random info 2
RandomInfo
我想对文本文件中的数千个此类实例执行此操作。在 Notepad++ 上我需要“查找和替换”什么?
谢谢!
答案1
- Ctrl+H
- 找什么:
(?:Name =|\G(?!^)) \K(\w)(\w+)
- 用。。。来代替:
\u$1\L$2
- 查看 环绕
- 查看 正则表达式
- 取消选中
. matches newline
- Replace all
解释:
(?: # non capture group
Name = # literally
| # OR
\G(?!^) # restart from last match position if not beginning of line
) # end group
# a space
\K # forget all we have seen until this position
(\w) # group 1, first letter
(\w+) # group 2, following letters
替代品:
\u$1 # uppercased 1rst letter
\L$2 # lowercased ather letters
截图(之前):
截图(之后):