Multi line search and replace

Say I have the following code:

Test.prototype.doSomething = _.debounce( function() {
}, 500);

How can I replace the number 500 to 10 in all the files of my project? I can't see to find a way to use regular expression with multi-lines support.

Comment actions Permalink

Hi there,

If you select your text .. and then invoke "Replace in Path" shortcut (Ctrl+Shift+R on Windows/Linux using Default keymap) IDE will be in regex mode straight away with your multi-line text properly escaped:

Comment actions Permalink

Thank you Andriy, I wasn't aware of this feature.

However, when I try to use .* to match anything including newlines, it doesn't seem to work. Is there a way for the dot to match newlines as well?

This is the expression I used to match the code I posted above:

(Test\.prototype\.doSomething \= .*) (500)(\)\;)

And my replace string would be something like:

$1 10$3
Comment actions Permalink

Accordingly to the devs comments (quite old, actually) -- not possible. The dot (.) symbol will NOT match new lines (\n)

In my practice -- such restriction makes sense (otherwise .* would cause too many issues) .. although some check box to lift it up would be good to have for those who needs it.

Comment actions Permalink

Thanks for your help, I'll be looking for an alternative then. Too bad the dev team seems to be ignoring this issue :(

Comment actions Permalink

Selecting the multi-line text and Ctrl+Shift+R worked like a charm for me on a more simple text phrase.





appeared as: 

Line1\n  Line2


in the pre-populated window and the replace worked perfectly.  Thanks Andriy!

Comment actions Permalink

use [\s\S]* instead of .* to consider \n too

text: Some multi- \n line text \n  example please

regex : me[\s\S]*?pl


me multi-
line text

Comment actions Permalink

Found this thread while trying to search for my issue but ended up finding it anyway. My use-case is be able to find the @Bean and Generator in the same code block that lives on two separate new lines. For example, being able to find the first to lines in: 

public Generator generatorResolver() {
return new Generator();

In the Find in Path pop up, the regex I use is: 


It works like a charm; thank you for the hints. 


Comment actions Permalink

Thanks Wendigoxs! [\s\S]* is the solution!

Comment actions Permalink

I landed here after a search to work out how to make the "." in a regex match newlines.

However then solved my problem using this which will match all chars including newlines:


Thought this was maybe worth recording here.

Comment actions Permalink

If you are trying to make the . character match newlines (similar to DOTALL mode in Java) you may find this useful.

As the docs say:

IntelliJ IDEA supports all the standard regular expressions syntax

This means you can use modifiers such as (?s) a the start of the expression which:

makes the dot match all characters, including line breaks


Please sign in to leave a comment.