Problem

Today in work I got a nice task.

For given  image

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:

image

Should Transform to:

image

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

image

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. (?.*)/(?.*) </strong>This will match everything to last possible “/” and make group named path, then every character after “/” is put into end group.

Replace Expression

image

Replace expression uses matched groups like simple variables to construct new Path.

The end result is

image

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

Rad Software Regular Expression Designer