开发者

How can I reverse this Regex?

I've got a successful match on:

/^\/?build\/(.+\.coffee|.+\.sass|.+\.erb)$/

Now I want to find all file开发者_高级运维s under /build/ that DON'T match either of those extensions. I think I can do this with negative look-ahead but I can't seem to get it working.

Any thoughts?


if you find all files under /build/ and DON'T match either of those extensions,you'd better use "?!" to except string,for example:

^\/?build\/(?:(?!\.coffee|\.sass|\.erb).)*$


extensions = [".coffee",".sass",".erb"]
Find.find(build_folder) do |file|
  next unless extensions.include?(File.extname(file))
end

Also, do you know of this?

if some_string =~ /some_regex/
  # matched regex
end

if some_string !~ /some_regex/
  # didn't match regex
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜