Suppose infile is a variable containing the name of the input file and a similar outfile for the output file. If the infile ends with .js , I would like to replace .min.js and it is quite simple (I think).
outfile = re.sub (r '\ b.js $', '.min.js', infile)
But my question is: if the infile ends in .min.js , then I do not want the replacement to be done. (Otherwise, I ended up with .min.min.js ). How can I do this using regex?
PS: This is not homework. If you are wondering what it is for: this is for a small python script for massively compressing JavaScript files in a directory.
source
share