正则表达式删除最后一个换行符

Given the following ; delimited string


a;; z
toy;d;hh 
toy
;b;;jj
z;
d;23
d;23td
;;io;
b y;b;12
z
a;b;bb;;;34
z

和这个正则表达式

^(?!(?:(a|d))(?:;|$)).*(\s*\z|$)\R*

I am looking to get the full lines whose 1st. column is not a or d, and have the matching lines removed, like this

a;; z
d;23
d;23td
a;b;bb;;;34

Please see the demo

在演示中,“替换”面板中有第5个空行,我想删除该行。

I have used this \s*\z in this past for this purpose. As implemented here, it does not seem to work.

任何帮助表示赞赏