adamreisnz / replace-in-file

A simple utility to quickly replace contents in one or more files
580 stars 65 forks source link

Use regexp remembered string? #109

Closed katyapavlenko closed 4 years ago

katyapavlenko commented 4 years ago

I tried to use something like

replace({
    files: __dirname + '/**/*.ts',
    from: new RegExp(`` + oldFileName + `(['"])`, 'gi'),
    to: oldFileName + $1
  })

but it results not using regexp memory, and $1 is inserted as a string. Is there a way to use regexp remember features?

adamreisnz commented 4 years ago

This is probably what you're after: https://github.com/adamreisnz/replace-in-file#using-callbacks-for-to