%r{ # Use %r{} instead of /…/ so we don't have to escape slashes
\A # Make sure we start at the front of the string
(?!rails_admin) # NOW ensure we can't see rails_admin from here
([^_/]|/[^_]) # (I have no idea what your logic is here)
([^/]*) # the file name
\.s?css # the extension
\z # Finish with the very end of the string
}x # Extended mode allows us to put spaces and comments in here
请注意,在 Ruby 正则表达式中^
并$
匹配行的开始/结束,而不是字符串,因此通常最好使用\A
and\z
来代替。
编辑:这是一个允许任何路径的修改版本:
%r{ # Use %r{} instead of /…/ so we don't have to escape slashes
\A # Make sure we start at the front of the string
(?!rails_admin) # NOW ensure we can't see rails_admin from here
(.+/)? # Anything up to and including a slash, optionally
([^/]*) # the file name
\.s?css # the extension
\z # Finish with the very end of the string
}x # Extended mode allows us to put spaces and comments in here
根据您的编辑和评论,这是一个匹配的正则表达式:
- 任何以 .css 或 .scss 结尾的文件
- 但如果路径以
rails_admin
- 而不是如果文件名以下划线开头
%r{ # Use %r{} instead of /…/ so we don't have to escape slashes
\A # Make sure we start at the front of the string
(?!rails_admin) # NOW ensure we can't see rails_admin from here
(?:.+/)? # Anything up to and including a slash, optionally (not saved)
(?!_) # Make sure that we can't see an underscore immediately ahead
([^/]*) # the file name, captured
\.s?css # the extension
\z # Finish with the very end of the string
}x # Extended mode allows us to put spaces and comments in here