首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >咕哝:用一行替换特定的单词

咕哝:用一行替换特定的单词
EN

Stack Overflow用户
提问于 2014-12-19 09:28:56
回答 1查看 615关注 0票数 0

下面是一个类,我只想从这个类中替换特定的行。

代码语言:javascript
复制
class abc{

  Rest of code...

  Titan.include('`MyFunction/myControl`.js');

  Rest of code...

}

我希望将Titan.include替换为myfunc,并从行中删除".js“一词:

代码语言:javascript
复制
myfunc('`MyFunction/myControl`');

我正在使用grunt.loadNpmTasks('grunt-string-replace');

任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-20 02:19:52

如果您使用咕噜-文本-替换插件,您可以按以下方式配置它:

代码语言:javascript
复制
replace: {
      myReplace: {
        src: [ 'yourFile' ], //your file
        dest: 'destinationFile', //path and namefile where you will save the changes.
        replacements: [ {
          from: /Titan\.include\('(.*)\.js'\);/g,   //Regexp to match what you need
          to: "myfunc('$1');"   //Replacement for the Regexp
        } ]
      }
    }

无论如何,我从来没有使用过咕噜-字符串-替换插件,但如果你需要用它代替咕噜-文本-替换我的东西应该这样工作:

代码语言:javascript
复制
'string-replace': {
  dist: {
    files: {
      'dest/': 'yourfile' //Key: path  where you will save the changes. Value: File or path where you will search.
    },
    options: {
      replacements: [{
        pattern: /Titan\.include\('(.*)\.js'\);/g,
        replacement: "myfunc('$1');"
      }]
    }
  }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27563046

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档