Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
910 views
in Technique[技术] by (71.8m points)

intellij 15 - VS Code Regex find and replace with lowercase, use l or L if possible

Is there a way to do a find and replace (regex) all uppercase characters in the matching strings with lowercase ones? Preferably in VS Code or IntelliJ I already have my regex ready.

Edit: To be clear I already know who to find the matches. But looking for that function to replace all uppercase matches with lowercase ones

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is support for the case modifiers L, l, U and u Find/Replace (from Build 1.47 for replacing strings in an editor, and from Build 1.49 it also works in the Find/Replace across the workspace (see https://github.com/microsoft/vscode/pull/105101)).

So you just have to put the l modifier in front of all your matched uppercase groups, like

l$1 see regex101 demo1

or just put the L in front of it all, like L(rest of replace here). see regex1010 demo2


Note that these modifiers work a little differently than you might be used to. For instance:

(de)(pth) Search

U$1$2 Replace

DEPTH expected result

DEpth vscode result

The case modifier only works on the immediate capture group. Not until it encounters E or the end of the replace string.

I assume for this same reason E isn't implemented in vscode at all, as it would be irrelevant given that only the immediate capture group is modified.

So to get DEPTH as the result you should use U$1U$2.

The modifiers can also be stacked - for example, uuu$1 will uppercase the first 3 characters of the group, or lU$1 will lowercase the first character, and uppercase the rest.

Currently, these are only supported in the editor's find widget, and not in "Find in Files".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...