Search code examples
javascriptregexminify

regex to target .min.js. extensions in file url


min.js files in a wordpress site and my caching plugin says "Enter the URL of JS files to reject (one per line). You can use regular expressions (regex)."

Is there a way too put in a url with regex and target all files that have .min.js in them so I can exclude them all at once?

The same is also for .min.css files.

thanks!


Solution

  • The regex you are looking for looks like this:

    ^.+\.min\.(js|css)$
    

    The explanation from regex101.com. I'll just past it here, since I can't do a better job:

    • ^ assert position at start of the string
    • .+ matches any character (except newline)
      • Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
    • \. matches the character . literally
    • min matches the characters min literally (case sensitive)
    • \. matches the character . literally
    • 1st Capturing group (js|css)
      • 1st Alternative: js js matches the characters js literally (case sensitive)
      • 2nd Alternative: css css matches the characters css literally (case sensitive)
    • $ assert position at end of the string