How can I use regex to replace upper case with lower case in Intellij IDEA?

I searched this for a search and found out how to do this with other regex parsers:

http://vim.wikia.com/wiki/Changing_case_with_regular_expressions http://www.regular-expressions.info/replacecase.html 

I tried and did not work. As an example, I want to use a regex to change this:

 private String Name; private Integer Bar = 2; 

For this:

 private String Name; private Integer Bar = 2; 

I tried something like this:

 replace: private (\S+) (\S+) with: private $1 $L$2 with: private $1 \L$2 with: <etc.> 

None of them work. Is it possible to do this in intellij, or is it a missing function? This is for educational purposes only, and this example is contrived. I just want to know if this can be done in intellij.

+42
java regex intellij-idea
Jun 10 '14 at 20:08
source share
3 answers

In IDEA 15, you can use the switches below to switch the case of captured expressions. This is now officially documented since the release of this version.

  • \l : omit the next character
  • \u : in case of the next character
  • \l : Leave the bottom characters of the following characters until \E or the end of the replacement string
  • \u : until the following characters appear before \E or the end of the replacement string
  • \E : mark the end of a case change initiated by \u or \l

Here is a usage example (as the documentation is not clear):

find: (\ w + _) + (\ w +) replace: \ L $ 1 $ 2 \ E

The above converts FOO_BAR_BAZ to FOO_BAR_BAZ , etc. $ 1 refers to the first capture group found (in brackets), $ 2 to the second set, etc.

For posterity: this was originally reported by @gaoagong and documented there .

+74
Aug 21 '15 at 9:42 on
source share

I was looking for the answer, and then I realized that @ ajp15243 already answered this above. Intellij has no way to use the regex function to change the case of a letter. The following is a brief discussion of the following URL for this function.

http://www.jetbrains.com/idea/webhelp/regular-expression-syntax-reference.html

You can also vote for this feature in Youtrack:

http://youtrack.jetbrains.com/issue/IDEA-70451

There is a Regex Intellij plugin, but, alas, it also does not support the lower and upper casings.

http://plugins.jetbrains.com/plugin/19?pr=idea

You just need to run the files through the perl program in order to replace them correctly.

+13
Jun 11 '14 at 5:55
source share

I started using the Idea Vim plugin and learning how to do things like that in Vim. That way, I could reuse these skills outside of the idea.

Here is the vim command to execute what you requested.

 :%s/private\s\(\w*\)\s\(w*\)/private \1 \L\2/g 

The regular expression is entered in the IDE. Additional slashes are needed to avoid the regex pattern in Vim.

Within the IDE

Find a plugin from the IDE. enter image description here

+5
Apr 16 '15 at 7:26
source share



All Articles