How to replace all text between two phrases with regular expressions in Notepad ++ or Textpad?

I have about 50 html documents and I need to replace the text between

<!DOCTYPE

and

<!-- start content -->

with

<?php require("header.php"); ?>

From what I read, Notepad ++ does not support multiple lines of regular expressions, but I thought I could put this in the question as well. I am new to regex, so I need someone to tell me how to do this. Thanks in advance!

+4
source share
1 answer

I don't have Notepad ++ or Textpad, so I can’t say for sure, but one of the following may work there:

Search

  • <!DOCTYPE[\s\S]*?<!-- start content --> or
  • <!DOCTYPE.*?<!-- start content --> with the option "Match newline" or
  • (?s)<!DOCTYPE.*?<!-- start content -->

and replace it with <?php require("header.php"); ?> <?php require("header.php"); ?> .

This will remove everything between the two phrases (including the phrases themselves). If you don't want this (I'm not sure about your question), then you probably want to keep what is in the first line after <!DOCTYPE , right? So:

Find (<!DOCTYPE[^\r\n]*)[\s\S]*?<!-- start content --> (or (?s)(<!DOCTYPE[^\r\n]*).*?<!-- start content --> etc.),

and replace with $1<?php require("header.php"); ?><!-- start content --> $1<?php require("header.php"); ?><!-- start content -->

+1
source

All Articles