将第一个小写转换为大写,将大写转换为小写(正则表达式?) [英] Convert first lowercase to uppercase and uppercase to lowercase (regex?)
问题描述
在此布局中,我有一个很大的文件:
I have a huge file in this layout:
world12345:Betaalpha
world12344:alphabeta
world12343:ZetaBeta
world12342:!betatheta
我需要将:"之后的第一个小写字母转换为大写字母,并将第一个大写字母转换为小写字母. 我曾经尝试过使用notepad ++和emeditor,但是对正则表达式的经验并不丰富.
I need to convert the first lowercase letter after the ":" to uppercase and the first uppercase letter to lowercase. I've tried using notepad++ and emeditor, but I'm not that experienced with regex.
这就是我希望它成为(正则表达式)之后的方式
This is how I want it to become after (regex?)
world12345:betaalpha
world12344:Alphabeta
world12343:zetaBeta
world12342:!betatheta (unchanged, as the first char is a special char)
我尝试在网络上搜索npp +中的正则表达式,但无济于事. 不幸的是,我不是脚本编写者,所以我自己也不能自己写.
I have tried searching the web for a regex in npp+, but to no avail. Unfortunately, I'm not a scripter so I can't write one myself.
提前谢谢!
推荐答案
感谢此答案,我能够在最初认为不可能的情况下找到解决问题的方法.
Thanks to this answer, I was able to find a solution to your problem after initially thinking it wasn't possible.
在Notepad ++中执行此操作的方法是使用以下选项:
The way to do this in Notepad++ is to use the following options:
- 打开替换"对话框( Ctrl + H )
- 查找内容:
^([^:]+:)(([A-Z])|([a-z]))([^:]+)$
- 替换为:
$1\L$3\E\U$4\E$5
- 检查匹配情况
- 检查环绕
- 选择正则表达式
- 取消选中.匹配换行符
- 按全部替换
- Open the Replace dialog (Ctrl + H)
- Find what:
^([^:]+:)(([A-Z])|([a-z]))([^:]+)$
- Replace with:
$1\L$3\E\U$4\E$5
- Check Match case
- Check Wrap around
- Select Regular expression
- Uncheck . matches newline
- Press Replace All
以下是此操作的GIF:
Here's a GIF of this in action:
查找内容字段的细分:
-
正则表达式前面的
-
^
代表行的开头,结尾的$
代表行的结尾.这样可以防止它变得懒惰或换行. -
([^:]+:)
代表该行开头的字符,允许除:
之外的所有字符.这是组$1
-
(([A-Z])|([a-z]))
表示:
之后的第一个字符.如果除了大写或小写字母外,其他任何内容都将跳过该行.- 组
$2
将是第一个字符,无论大小写如何.我们将在替代产品时忽略它. - 组
$3
如果是大写字母,将是第一个字符,否则$3
将为空. - 组
$4
如果是小写字母,将是第一个字符,否则$4
将为空.
^
at the front of the Regular Expression represents the beginning of a line and$
at the end represents the end of a line. This prevents it from being lazy or wrapping to the next line.([^:]+:)
represents the characters at the beginning of the line, allowing all characters except:
. This is group$1
(([A-Z])|([a-z]))
represents the first character after the:
. If there is anything other than an upper or lowercase letter, it will skip the line.- Group
$2
will be the first character, regardless of uppercase or lowercase. We'll ignore this in our replacement. - Group
$3
will be the first character if it is uppercase, otherwise$3
will be empty. - Group
$4
will be the first character if it is lowercase, otherwise$4
will be empty.
替换为字段的明细:
-
$1
将是如上所述的第一组 -
\L$3\E
将如上所述将组$3
转换为小写. -
\U$4\E' will convert group
$ 4`如上所述,为大写字母. -
$5
将是如上所述的最后一组
$1
will be the first group as described above\L$3\E
will convert group$3
as described above to lowercase.\U$4\E' will convert group
$4` as described above to uppercase.$5
will be the last group as described above
\L
和\U
分别表示开始转换为小写"或大写".\E
代表停止转换".由于$3
或$4
中只有一个包含第一个字符(另一个将为空白),因此仅在需要时才进行转换.\L
and\U
stand for "beginning converting to lowercase" or "uppercase," respectively.\E
stands for "stop converting." Since only one out of$3
or$4
will contain the first character (the other will be blank), this converts only in the case we want.这篇关于将第一个小写转换为大写,将大写转换为小写(正则表达式?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- Group
- 组