Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个包含以下内容的文件:
Apple 'BANANA' ORANGE 'PEACH'
将所有引用的大写字母转换为小写字母的正则表达式是什么?
预期的输出文件应如下所示:
Apple 'banana' ORANGE 'peach'
尝试
:%s/'\w\+'/\=tolower(submatch(0))/g
'\w\+'匹配引号内的任何单词。并将其替换为匹配的小写版本。\=告诉substitute 评估将(整个匹配)中tolower(submatch(0))找到tolower()的字符串转换submatch(0)为小写的表达式。
'\w\+'
\=
tolower(submatch(0))
tolower()
submatch(0)
您也可以使用\L原子将其后面的字符串转为小写,\0与submatch(0)
\L
\0
:%s/'\w\+'/\L\0/g
看一眼:h s/\L
:h s/\L