Change RegExp['$n']  to RegExp.$n