我想使用正则表达式将大写字母更改为小写单词
<title>THE CHILDREN are at home.</title>
成为
<title>The children are at home.</title>
因此,我编写了一个 Python 脚本来完成这项工作:
page_title = 'THE CHILDREN are at home.'
title_words = page_title.split(' ')
new_title_words = list()
for w in title_words:
if w.isupper():
new_title_words.append(w.lower().capitalize())
else:
new_title_words.append(w)
page_title = " ".join(new_title_words)
print(page_title)
但我想使用 notepad++ 的正则表达式,而不是 Python。有人能帮我吗?
答案1
- Ctrl+H
- 找什么:
(?:<title>.|\G)\h*\K[A-Z]+
- 用。。。来代替:
\L$0
- 查看 相符
- 查看 环绕
- 查看 正则表达式
- 取消选中
. matches newline
- Replace all
解释:
(?: # non capture group
<title> # literally
. # any character
| # OR
\G # restart from last match position
) # end group
\h* # 0 or more horizontal spaces
\K # forget all we have seen until this position
[A-Z]+ # 1 or more capital letters
替代品:
\L # lowercased
$0 # the whole match
截图(之前):
截图(之后):