简体   繁体   English

正则表达式排除文件模式

[英]Regex to exclude file pattern

I have the following regex which I want to ignore sass partials: 我有以下正则表达式,我想忽略sass部分:

At the moment it looks like this: 现在看起来像这样:

  match /app\/stylesheets\/(?:.+\/)?[^_].+\.s[ca]ss/ do
    sass
  end

Example file paths I want to parse are: 我要解析的示例文件路径为:

/app/stylesheets/nonpartial.scss
/app/stylesheets/folder/anothernonpartial.scss

And examples of the partials I want to ignore are 我想忽略的局部的例子是

/app/stylesheets/_partial.scss                   #this is ignored
/app/stylesheets/partials/_anotherpartial.scss   #this gets a match

The partials are not getting picked up by the regex, can anyone suggest a better one? 正则表达式不会提取局部词,有人可以建议一个更好的词吗?

/app\/stylesheets(\/(\w+?))*\/(?!_)(\w+?)\.s[ca]ss/

This RegEx will match a file in /app/stylesheets in an arbitrary number of subdiretories whereas the filename must not begin with an underscore. 此RegEx将匹配/ app / stylesheets中任意子目录中的文件,而文件名不得以下划线开头。

This RegEx uses Look-Arounds . 此RegEx使用Look-Arounds

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM