我不完全确定OP的目的是什么,但您希望将所有行与以下内容匹配
Grant access to Server1
Grant access to Server2
Grant access to Server3
Grant access to Server4
你可以用这个作为你的模式
(Grant access to Server\d+(\n)?){4}
。这将匹配原始文本“授予对服务器的访问权限”,后跟至少一个数字。如果最后一项位于字符串末尾(最后一项不会有换行符),我们将包含可选项
(\n)?
对于换行符。最后,由于示例中只有4次出现,因此{4}的限定符。你可以很容易地用*代替{4},作为对所有事件的贪婪捕捉
按顺序排列
.
所以
(Grant access to Server\d+(\n)?)*
也将匹配:
Grant access to Server1
Grant access to Server3
Grant access to Server44325
Grant access to Server4
Grant access to Server44
Grant access to Server3