Replace $n regex variables with use of MatchData object.