SovietFrontier
SovietFrontier

Reputation: 2217

How to replace parts of a line with search/replace in Intellij?

I am trying to find all cases of println and replace them with log.debug() for starters, then clean up the logs. Is there a tool somewhere than can help me do that? Is this even possible? We are trying to replace both the beginning of a line with log.debug( AND the end of it, with the ).

We are on:

Groovy 2.5.11
Java 1.8
IntelliJ IDEA 2020.2.1 (Ultimate Edition) Build #IU-202.6948.69
Windows OS

Example:

//find all instances of (text in logs is varied)
println "this is a log"

//and replace with
log.debug("this is a log")

Upvotes: 1

Views: 53

Answers (1)

CrazyCoder
CrazyCoder

Reputation: 401975

  • Search pattern: println "(.*?)"
  • Replace pattern: log.debug("$1")

Replace in path

Notice the regex search option is enabled (.* icon on the right).

More details in IntelliJ IDEA documentation.

Upvotes: 2

Related Questions