Replace Lines of Code

Tool for Search and Replace across multiple files.
Post Reply
Steve_L
Posts: 4
Joined: Sat May 25, 2013 12:59 am

Replace Lines of Code

Post by Steve_L »

I am looking to replace a lot of code in a bunch of pages. What I am trying to do is replace everything above and including this line <!--**************BEGIN CONTENT*************-->

And I would like to replace it with another block of html code. Having trouble trying to figure out how to remove the code above a the line mentioned above and replace it. Will also have to do the same for the code below the content area as well.

Any help would be appreciated.

Trying to change the look of web pages I am working on while keeping the content section as is. I have about 100 web pages to do this, and would be great to automate it.
Steve_L
Posts: 4
Joined: Sat May 25, 2013 12:59 am

Re: Replace Lines of Code

Post by Steve_L »

Ok...I think I have found a way to do this....if anyone has a better way feel free to share. I searched for a long time about regular expressions and was able to come up with this.

*********************************
To remove everything above a certain line, including spaces and the line you specify.

Example:
([\s\S]*)\<\!\-- C O N T E N T B E L O W T H I S L I N E \--\>

*********************************
To remove everything below a certain line, including spaces and the line you specify.

Example:
\<\!\-- C O N T E N T A B O V E T H I S L I N E \--\>([\s\S]*)

*********************************
To remove everything above and below a certain line, including spaces.

Example:
([\s\S]*)\<\!\-- C O N T E N T B E L O W T H I S L I N E \--\>|\<\!\-- C O N T E N T A B O V E T H I S L I N E \--\>([\s\S]*)

*********************************
If you want to remove everything above a certain line and remove the spaces, but keep the line you can do it this way.

Example: This will remove everything above the body tag, but keep the body tag in place.
(?s).*?(?=\<body\>)

*********************************
Hope this helps someone....took me a while to find it as I am not fluent in using RegEx.
Post Reply