views:

81

answers:

1

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've read, Notepad++ does not support multiple line regular expressions but I thought I might put that in the question too. I'm new to regular expressions so I need someone to tell me how to do this. Thanks in advance!

+1  A: 

I have neither Notepad++ nor Textpad installed, so I can't say for sure, but one of the following might work there:

Search for

  1. <!DOCTYPE[\s\S]*?<!-- start content --> or
  2. <!DOCTYPE.*?<!-- start content --> with the "Dot matches newline" option set or
  3. (?s)<!DOCTYPE.*?<!-- start content -->

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

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

Search for (<!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 -->

Tim Pietzcker
Grr... For some reason, none of those work in either Textpad or Notepad++. I thought that Textpad supported multi line regex. Can you recommend a text editor that does?
Will X
[EditPadPro](http://www.editpadpro.com) is the editor with the best regex support of all.
Tim Pietzcker
Okay now I think i'm just doing something wrong because these don't work in editpadpro either...I'm probably just making a dumb mistake.
Will X
What exactly do you mean by "don't work"? Do they match too much, too little or nothing at all?
Tim Pietzcker
None of them were able to find any text. They didn't match anything.
Will X
Oops. I just realized that I have missed `--` in the `start content` bit. My bad. I have edited my answer and hope it works now. Sorry.
Tim Pietzcker
Actually I noticed that so I just searched for <!-- start content. I found another utility called grepwin and the regex works very well in it! I guess it was just Textpad and Notepad++ that weren't doing so well. Thanks a lot!
Will X
Great. But it should have matched in EditPadPro, too (you need to check the "Regular Expression" checkbox in the search field, though).
Tim Pietzcker