【问题标题】:Regex for .less extension file that excludes .module.less不包括 .module.less 的 .less 扩展文件的正则表达式
【发布时间】:2019-02-22 07:11:48
【问题描述】:

我正在尝试创建一个正则表达式,它将匹配以 .less 结尾但不以 .module.less 结尾的字符串。

现在我可以用这个正则表达式/^(?!.*[.]module[.]less$)/ 来表达不以.module.less 结尾。

我使用 JavaScript 作为一种语言。我该怎么做?

我想要什么

  • “style.module.less”????
  • "style.less" ✅
  • “index.js”????

提前致谢

【问题讨论】:

  • /^(?!.*\.module\.less$).*\.less$/

标签: javascript regex regex-negation


【解决方案1】:

您的前瞻正则表达式只会阻止匹配以 .module.less 结尾的字符串。

您可以在消费部分添加.*\.less$

/^(?!.*\.module\.less$).*\.less$/
                       ^^^^^^^^^ 

It will only match strings ending with .less now.

.* 模式将贪婪匹配整个字符串,\.less$ 将匹配字符串末尾的 .less (\.less) ($)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-26
    • 2010-09-19
    • 1970-01-01
    • 2012-02-13
    • 2010-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多