Search code examples
searchreplacephpstormnewline

PhpStorm new line in HTML replace


For over a year I have been trying to do the simplest thing - do an HTLM/PHP search and replace in several files.

For exapmle if I want to replace

<!DOCTYPE html>

with

<!DOCTYPE html>
<!--
TODO UNIVERSAL
Favicon
Page title
Active page
-->

I get

<!DOCTYPE html> <!--     TODO UNIVERSAL     Favicon     Page title     Active page   -->

I realize search and replace is probably considered old fashioned but I have found it an incredibly useful tool for 30 years.

I have scoured JetBrains web site with no avail and searched here and elsewhere.

I have tried /n, \n, \\n, \\n\\r etc etc and nothing seems to work.

I am sure I am being a dunce but could some other PhpStorm user please enlighten me.


Solution

  • Search for:

    \<\!DOCTYPE HTML\>
    

    Replace with:

    \<\!DOCTYPE html\>\n\<\!\-\-\nTODO UNIVERSAL\nFavicon\nPage title\nActive page\n\-\-\>
    

    Make sure that Regex option is checked

    enter image description here

    (here on screenshot you see the result of such replacement)


    P.S. PhpStorm (and other IDEA-based IDEs) uses \n internally (while editing) for all line endings. And then, when saving, it uses detected/proper line ending.