0

I need to replace all occurrences of a word for another in all txt files. That works if I put like that:

const replace = require('replace-in-file');
const options = {
    files: './**/*.txt'
    from: /oneWord/g,
    to: 'anotherWord,

}; 

But, I need to use App' user input with process.argv[], and I could not find how to replace the

from: /oneWord/g, 

for

from: '/'+ process.argv[3] + '/g'

const replace = require('replace-in-file');
var from = '/'+ process.argv[3] + '/g';
const options = {
files: process.argv[2],
from: process.argv[3],
to: process.argv[4],

Any help?

Vega
  • 27,856
  • 27
  • 95
  • 103
  • Here is link about how to do it. https://stackoverflow.com/questions/874709/converting-user-input-string-to-regular-expression. And here is link to RegExp manual https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp – Vayrex Mar 25 '18 at 21:37

1 Answers1

0

In the options you must put your variable from instead of process.argv[3].

tintef
  • 178
  • 2
  • 9