简体   繁体   English

带有资源查询的 css 文件的正则表达式

[英]Regular expression for css file with resourcequery

what would be the regex to include files like什么是包含文件的正则表达式

'../../cloud.css?raw'

I have ^.+\\.(css|sass|css?raw)$ but seems it is not correct for above path.我有^.+\\.(css|sass|css?raw)$但似乎上面的路径不正确。 whatwould be the regex toincludes file with.css?raw extenssion??包含文件的正则表达式是什么。css?原始扩展名?

This is better, you need to escape ?这样比较好,你需要逃跑? and you had a double \\ : ^.+\.(css|sass|css\?raw)$你有一个双\\ : ^.+\.(css|sass|css\?raw)$

A really good tool to try: https://regex101.com/一个非常好的尝试工具: https://regex101.com/

Example https://regex101.com/r/a2tAg7/1示例https://regex101.com/r/a2tAg7/1

Also if you don't need to capture, you can use a non-capturing group, this is even better: ^.+\.(?:css|sass|css\?raw)$ and finally .+ is not needed as you have the end of match character here $ .此外,如果您不需要捕获,您可以使用非捕获组,这会更好: ^.+\.(?:css|sass|css\?raw)$最后.+不需要你在这里有匹配字符的结尾$

You might also want to match ?raw on sass as well?您可能还想在 sass 上匹配?raw吗?

So imo, best would be \.(?:css|sass)(\?raw)?$ Here is another example: https://regex101.com/r/V194mv/1所以imo,最好是\.(?:css|sass)(\?raw)?$这是另一个例子: https://regex101.com/r/V194mv/1


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

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