Coffeescript 需要单独文件中的正则表达式块

Coffeescript 需要单独文件中的正则表达式块,coffeescript,Coffeescript,如何在单独的文件中编写coffee脚本regex块,并在需要时需要该文件?我有很多,最好把它们放在一个单独的地方 编辑: 我想保留以下内容: texInputsPattern = /// (.*[A-Za-z0-9_]\/\/:$) # Ensure last three characters are '//:' /// 在一个单独的文件中。咖啡。我试过: module.exports= texInputsPattern = /// (.*[A-Za-z0-9_]\

如何在单独的文件中编写coffee脚本regex块,并在需要时需要该文件?我有很多,最好把它们放在一个单独的地方

编辑: 我想保留以下内容:

texInputsPattern = ///
  (.*[A-Za-z0-9_]\/\/:$) # Ensure last three characters are '//:'
  ///
在一个单独的文件中。咖啡。我试过:

module.exports=
    texInputsPattern = ///
      (.*[A-Za-z0-9_]\/\/:$) # Ensure last three characters are '//:'
      ///
    anotherPattern1 = ///
      ... # 
      ///
    anotherPattern2 = ///
      ... # 
      ///
    anotherPattern3 = ///
      ... # 
      ///
    ...
然后在main.coffee我试着:

我还尝试:

_ = require 'underscore-plus'

_.clone(require('./patterns))


module.exports = 
...

我接到一个关于意外/的投诉。我的问题是如何保存patterns.coffee这样的文件并将模式包含在main.coffee中?

您似乎无法导入包含正则表达式的对象。您是否在节点或浏览器上运行browserify/webpack

这应该起作用:

咖啡

module.exports = 
  a: /\d/
咖啡

regexes = require('./regexes')
console.log(regexes.a.test(1)) # True
console.log(regexes.a.test('a')) # False

请添加更多相关信息。您使用的是构建过程还是模块系统?需要,浏览,网页?你试过什么但失败了吗?@gadr90:请看我的编辑。
regexes = require('./regexes')
console.log(regexes.a.test(1)) # True
console.log(regexes.a.test('a')) # False