Hello, @dr-ramaanand, @alan-kilborn, @peterjones and All,
@dr-ramaanand, here is my only contribution to your problem :
If you’ll find this solution insteresting, just be nice and make a donation to @Don-ho. It’s, I think, the least you can do !
If I assume that :
There is only 1 concerned zone, of consecutive <H2>.......</H2> blocks, located right after the <H1>.......</H1> block
The text of these <H2>.......</H2> blocks must be copied before the last line of your file which contains the string Please E-Mail us
And that your INPUT text is :
<H1........>Heading1</H1> <H2........>Some text</H2> <H2........>Different text</H2> <H2........>Altogether different text</H2> Some paragraphs here </P> (or </ul>) <P..........><span..........><b>Please E-mail us</b></span></P> <H2........>Heading that should not be reproduced</H2> Some paragraphs here </ul> (or </P>) <P..........><b><span..........>Please E-mail us</span></b></P>Note : Each <H2>..........</H2> line may be preceded and/or followed with tabulation and/or space characters
Then :
Open a new tab
Paste the above INPUT text in this new tab
Open the Replace dialog ( Ctrl + H )
Select the Regular expression mode and tick the Wrap around option
Follow the road map, below
Note : I’ll use the free-spacing mode, (?x), in order to easily identify the main parts of the search regexes
With the first regex S/R, below, we’ll place the line @@@ right before the last line of the file containing the string Please E-mail us
SEARCH (?xsi) \A .+ \K (?= ^ <P .+ Please \x20 E-mail \x20 us )
REPLACE @@@\r\n
So, we get this temporary OUTPUT :
<H1........>Heading1</H1> <H2........>Some text</H2> <H2........>Different text</H2> <H2........>Altogether different text</H2> Some paragraphs here </P> (or </ul>) <P..........><span..........><b>Please E-mail us</b></span></P> <H2........>Heading that should not be reproduced</H2> Some paragraphs here </ul> (or </P>) @@@ <P..........><b><span..........>Please E-mail us</span></b></P>With the second regex S/R, below, we’ll recopy all the <H2>.......</H2> lines, located right after the <H1>.....</H1> block, just before the delimiter line @@@
SEARCH (?xsi) (?<= </H1> \r\n ) ( \s* (?: <H2.+?> .+? </H2> \s* )+ ) ^ .+ \K (?= @@@ \R)
REPLACE \1
And the obtain this temporary OUTPUT :
<H1........>Heading1</H1> <H2........>Some text</H2> <H2........>Different text</H2> <H2........>Altogether different text</H2> Some paragraphs here </P> (or </ul>) <P..........><span..........><b>Please E-mail us</b></span></P> <H2........>Heading that should not be reproduced</H2> Some paragraphs here </ul> (or </P>) <H2........>Some text</H2> <H2........>Different text</H2> <H2........>Altogether different text</H2> @@@ <P..........><b><span..........>Please E-mail us</span></b></P>Note that the line <H2........>Heading that should not be reproduced</H2>, which is not consecutive to the other H2 lines, is not re-copied, as expected !
Now, with the third regex S/R, below, we’ll just rewrite the text of all these <H2>.....</H2> blocks, in a single line :
SEARCH (?xi-s) .+ > (.+) </H2> \h* \R (?= ( (?: \h* <H2 .+ \R )+ )? @@@ \R )
REPLACE We have a \1?2, :.
We get the temporary OUTPUT :
<H1........>Heading1</H1> <H2........>Some text</H2> <H2........>Different text</H2> <H2........>Altogether different text</H2> Some paragraphs here </P> (or </ul>) <P..........><span..........><b>Please E-mail us</b></span></P> <H2........>Heading that should not be reproduced</H2> Some paragraphs here </ul> (or </P>) We have a Some text, We have a Different text, We have a Altogether different text.@@@ <P..........><b><span..........>Please E-mail us</span></b></P>Finally, with the fourth regex S/R , below, we simply add the leading <P........> part and delete the @@@ string, alltogether
SEARCH (?x-s) ^ ( .+) @@@ $
REPLACE <P whatever you need >\1
And here is your expected OUTPUT text :
<H1........>Heading1</H1> <H2........>Some text</H2> <H2........>Different text</H2> <H2........>Altogether different text</H2> Some paragraphs here </P> (or </ul>) <P..........><span..........><b>Please E-mail us</b></span></P> <H2........>Heading that should not be reproduced</H2> Some paragraphs here </ul> (or </P>) <P whatever you need >We have a Some text, We have a Different text, We have a Altogether different text. <P..........><b><span..........>Please E-mail us</span></b></P>Best Regards,
guy038