Hello, @frank-kirschner, @claudia-frank, @scott-sumner and All,
I thought about a third regex which, in addition, looks if :
The END:VCALENDAR string is preceded by a line-break
The BEGIN:VCALENDAR string is followed by a line-break
and, in replacement, this regex S/R adds a line-break, if not initially present, in O.P.'s text
So, assuming the four possible cases, below :
blah blah
bla bla blaEND:VCALENDAR
3F68636A-A88D-4B6D-95C7-DC5B65910335.ics ZÔúƒ4504b552cef6ac7c1141ef12fba9a94a ²VEVENT ZÚ p ZÚˆ3F68636A-A88D-4B6D-95C7-DC5B65910335€ $ (È„ P€ „ Í`õ ¢BEGIN:VCALENDARblah blah blah
bla bla...
blah blah
bla bla blaEND:VCALENDAR
3F68636A-A88D-4B6D-95C7-DC5B65910335.ics ZÔúƒ4504b552cef6ac7c1141ef12fba9a94a ²VEVENT ZÚ p ZÚˆ3F68636A-A88D-4B6D-95C7-DC5B65910335€ $ (È„ P€ „ Í`õ ¢BEGIN:VCALENDAR
blah blah blah...
bla bla...
blah blah
bla bla bla
END:VCALENDAR
3F68636A-A88D-4B6D-95C7-DC5B65910335.ics ZÔúƒ4504b552cef6ac7c1141ef12fba9a94a ²VEVENT ZÚ p ZÚˆ3F68636A-A88D-4B6D-95C7-DC5B65910335€ $ (È„ P€ „ Í`õ ¢BEGIN:VCALENDARblah blah blah
bla bla...
blah blah
bla bla bla
END:VCALENDAR
3F68636A-A88D-4B6D-95C7-DC5B65910335.ics ZÔúƒ4504b552cef6ac7c1141ef12fba9a94a ²VEVENT ZÚ p ZÚˆ3F68636A-A88D-4B6D-95C7-DC5B65910335€ $ (È„ P€ „ Í`õ ¢BEGIN:VCALENDAR
blah blah blah
bla bla...
then the regex S/R :
SEARCH (?s-i)((\R)?END:VCALENDAR).*?(BEGIN:VCALENDAR(\R)?)
REPLACE (?2:\r\n)\1\r\n\3(?4:\r\n)
would gives the following text ( four identical blocks of text ) :
blah blah
bla bla bla
END:VCALENDAR
BEGIN:VCALENDAR
blah blah blah
bla bla...
blah blah
bla bla bla
END:VCALENDAR
BEGIN:VCALENDAR
blah blah blah...
bla bla...
blah blah
bla bla bla
END:VCALENDAR
BEGIN:VCALENDAR
blah blah blah
bla bla...
blah blah
bla bla bla
END:VCALENDAR
BEGIN:VCALENDAR
blah blah blah
bla bla...
Et voilà !
Notes :
You may, either, click several times on the Replace button or once, only, on the Replace All button
In search :
First the (?s-i) modifiers forces :
The search to be performed in a sensitive way ( NON-insensitive ! )
The special dot character . to be considered as any single character, even an End of Line one
Then group 1 contains the string END:VCALENDAR, possibly preceded with a line-break
The part (\R)? ( identical to the form (\R){0,1} ) represents an optional line-break ( group 2 )
Now, the .*? part ( identical to .{0,}? ) stands for the smallest range of any character, between the two strings END:VCALENDAR and BEGIN:VCALENDAR
The group 3 contains the string BEGIN:VCALENDAR, possibly followed with a line-break
Finally, the part (\R)? ( identical to the form (\R){0,1} ) represents an optional line-break ( group 4 )
In replacement :
The conditional replacement feature (?2:\r\n), rewrites a line-break, only if group 2 ( \R ) does not exist, before the string END:VCALENDAR
The block \2\r\n\3 adds the strings END:VCALENDAR and BEGIN:VCALENDAR, separated with a line-break ( \r\n )
The conditional replacement feature (?4:\r\n), rewrites a line-break, only if group 4 ( \R ) does not exist, after the string BEGIN:VCALENDAR
Cheers,
guy038