Hello @jeff-Michaels, @alan-kilborn, @dinkumoil and All,
Congratulations to brilliantly achieve your goal from the link provided by @alan-kilborn ;-)) You seem to be a regex’s guru, too !
Regarding your solution, I suppose that the end should be \r\n ( instead of \r\t )
Now, I think that you can simplify your regex as :
(?xs-i) <pg \x20 (?: (?! </pg> ) . )*? BAR .*? BREAK .*? </pg> \R # Delete any <pg> section containing BAR and BREAK
Indeed, no need to be sure that the string </pg> does not occur between the words BAR and BREAK and between BREAK and </pg>. Once you get the good <pg...> block, with the negative look-ahead, the lazy quantifiers, coming next, forces the correct detection of that block !
You may use \R as is stands for any kind of line-break ( \r\n, \n and \r )
Note that I use the Free-spacing mode ( (?x... ) which allows to separate the main parts of the regex and allows comments after the # char
Best Regards,
guy038