not sure if this is the most elegant way, but the following regex would always have the same 2 matching groups, and captures the changing part of the 2 events in non-capturing groups:
(?:5014 DFSR The DFS Replication service is stopping communication with partner|5002 DFSR The DFS Replication service encountered an error communicating with partner) (.*) for replication group (.*)(?:. Partner DNS address:| due to an error.)
my test string was
5002 DFSR The DFS Replication service encountered an error communicating with partner hostxy for replication group group_z1. Partner DNS address: