英文:
Replace to Lower Case is not working in VS Code's Search View
问题
根据这个StackOverflow帖子,伴随着一个已合并并发布版本的GitHub PR链接,用户应该能够使用正则表达式在全局查找中将结果替换为小写。然而,这个功能对我来说不起作用,而我使用的VS Code版本要比这个发布的版本要晚得多(1.77.3)(1.47)。
您可以看到“HI”被替换为“\LHI”。
有人能解释一下如何替换为小写吗?请注意,我不打算使用命令面板中的“转换为小写”命令,因为那不会执行大规模的替换。
英文:
According to this StackOverflow post, accompanied by a link to a GitHub PR that has been merged and the version has been released, users should be able to replace the results in global find to lower case using Regex. However, this feature is not working for me, and I am using a much later version of VS Code (1.77.3) than this was released for (1.47).
You can see that "HI" is replaced with "\LHI".
Can someone please explain how to replace to lowercase? Note that I am not looking to use "Transform to Lowercase" command from the command palette, as that does not perform mass replace.
答案1
得分: 1
那种替换,使用\L$0
在搜索替换中不起作用。您可以将整个内容包装在一个捕获组中,如下所示:
(\b(?:HI|HELLO)\b(?![A-Z a-z]))
然后用\L$1
替换,它会按您的期望工作。$0
在替换字段中确实有效,但不能与\L
、\U
、\l
或\u
一起使用。
英文:
That kind of a replacement, using \L$0
doesn't work in the Search replace. You could just wrap the whole thing in a capture group like
(\b(?:HI|HELLO)\b(?![A_Za-z]))
and then replace with \L$1
and it works as you expect. $0
does work in the replace field just not together with \L
, \U
, \l
or \u
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论