Can this be done more easily using a Matcher? In any case, extract `entry.getKey()` as a variable?