// probably using an immutable structure we replace all at once.
// The region must be cloned because a subsequent match will update the
// region, resulting in the MatchData created here pointing at the
// incorrect region (capture/group).
Region region = matcher.getRegion(); // lazy, null when no groups defined
match.regs = region == null ? null : region.clone();
match.begin = matcher.getBegin();
match.end = matcher.getEnd();
match.pattern = pattern;
match.str = (RubyString)str.strDup(runtime).freeze(context);