Create nginx replace css stylesheet

I am using nginx with the HttpSubsModule to replace multiple CSS stylesheets for another. My regex

subs_filter '<link(.*)href="(.+\.css)([\?.]?[^"]*)(".*)>' '<link  href="new.css" rel="stylesheet" type="text/css">' irg;

      

It appears to be valid, but subs_filter doesn't work with it. Simpler forms such as

subs_filter (.*)css '<link  href="new.css" rel="stylesheet" type="text/css">' irg;

      

do work, but they catch a lot of false results.

How do I write this regex?

EDIT: The next version works on www.regexe.com replacing any css file link tag, but still doesn't work on nginx.

subs_filter '(<link.*href=")(.+\.css)([\?.]?[^"]*)(".*>)' '$1new.css$3$4' irg;

      

+3


source to share


1 answer


Try the following:

subs_filter '(<link.*?href=(.))[^"']+\.css([^"']+\2[^>]*?>)' '$1new.css$3' irg;

      

DESCRIPTION



Regular expression visualization

DEMO

https://regex101.com/r/aF2aU9/1

+1


source







All Articles