I'm learning regexs and file saving. As exercise, I wanted to turn every func in a file into function:
data.replace(/func\((.*)\)/g, 'function')
The problem is that the funcs in the file now end up like this:
var thisfunc = function {
}
Instead of this:
var thisfunc = function() {
}
How should I do it so that the regex only replaces the func keyword?
EDIT:
input:
fs.readFile(filename, 'utf8', func(err, data) {
if (err) throw err
console.log('OK: ' + filename)
var newData = data.replace(/func\((.*)\)/g, 'function')
console.log(newData)
})
var thisfunc = func() {
}