RegExp Fun–Match/Replace in lines without specific word
Problem
Today in work I got a nice task.
Make a RegExp to transform each line and Path value, In a way that not minified javascript files (without min.js extension) should point to /min/ folder.
For Example:
Should Transform to:
Because I love experimenting with Regular Expressions. I happily dropped everything and started looking for solution . This seemed pretty simple … but … i had to spent like 30 min to find it.
Solution
Expression
Most important part of this solution is (?!.*min) . This expression will try to look for min word in matched data and if it wont find it there whole match is discarded.
For further replacement procedure, I m specifying two matched groups that will be used to construct new Path. (?
Replace Expression
Replace expression uses matched groups like simple variables to construct new Path.
The end result is
Making RegExp is like scientific discovery or complex mathematic problem. You have to really think a lot to find a nice solution.
For experiments I recommend