Page 1 of 1

Replace Lines of Code

Posted: Sat May 25, 2013 1:06 am
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.

Re: Replace Lines of Code

Posted: Sun May 26, 2013 2:51 pm
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.