node.js fs remove some text



/* 购买成功 */
"TXT_IAP_SUCCESS" = "Purchase Successful";

/* 购买失败 */
"TXT_IAP_FAIL" = "Purchase Failed";

/* 回复购买记录 */
"TXT_RESTORE_PURCHASE" = "Restore Purchases";

/* 你已重新获得你已购买的东西。 */
"TXT_PURCHASE_RESTORED" = "You've restored your purchases.";

I am using the fs to edit the text file. I want to remove between /* and */ text. But I don't know how to do. Thanks

You could remove these commented lines use regex expression, please try following code snippet. The key point is regex /*.**/, it matches all commented parts.

var fs = require('fs');
fs.readFile('./test.js', 'utf-8', function(err, data) {
  if (err) throw err;
  var newValue = data.replace(//*.**//gim, '');
  fs.writeFile('./test.js', newValue, 'utf-8', function(err) {
    if (err) throw err;
    console.log('filelistAsync complete');
  });
});

Hope this would be helpful.

最新更新