简体   繁体   中英

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. whatwould be the regex toincludes file with.css?raw extenssion??

This is better, you need to escape ? and you had a double \\ : ^.+\.(css|sass|css\?raw)$

A really good tool to try: https://regex101.com/

Example 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 $ .

You might also want to match ?raw on sass as well?

So imo, best would be \.(?:css|sass)(\?raw)?$ Here is another example: https://regex101.com/r/V194mv/1


The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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