1

I am using sublime to list all my .js files in my application but I want to use regex to show only the files that are not minified. I want files returned that are [NOT].min[/NOT].js I am using [^(\.min)]\.js and it appears to work but am not sure if it is going to miss any files. Is there a better piece of regex to use here?

/showhouse-bootstrap-datepicker.js      want returned
/dataTables.bootstrap.js                want returned
/additional-methods.min.js              dont want returned
/bootstrap-switch.min.js                dont want returned

I thought the following would work but it returns all .js

(?!\.min)\.js
Pierce McGeough
  • 2,788
  • 8
  • 39
  • 60
  • Why d you think it would miss any files? – Severin Apr 18 '14 at 11:00
  • I am unsure of regex and am not sure if this will return all files that end in .js but not .min.js – Pierce McGeough Apr 18 '14 at 11:16
  • The [The Stack Overflow Regular Expressions FAQ](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean/22944075#22944075) has an answer which may be of interest: [match a string not containing a word](http://stackoverflow.com/q/406230) – aliteralmind Apr 18 '14 at 11:21
  • I seen that post earlier but it doesnt really work for me becuase it is sperate entries. I want to find ".js" – Pierce McGeough Apr 18 '14 at 11:31

2 Answers2

1

instead of doing it the not way , do it as a positive search.

[^(\.min)]\.js is what you have done. this will not match any file ending in js which have m or n or i in them. check it .

Use a regex like this .

(?<!\.min)\.js

demo here : http://regex101.com/r/rJ1jN3

aelor
  • 9,803
  • 2
  • 27
  • 43
0

Sublime Text uses the Boost regex syntax, so you could use a pattern that grouped the items matching *.min.js and/or *.js then use a backreference to match the sub-expression:

^(.+w+\.js)|(.+\w+\.min\.js)\1$

The first pattern ^(.+\w+\.js) groups anything matching *.js into sub-expression 1, the second pattern (.+\w+\.min\.js) puts any matching *.min.js into sub-expression 2. The final step is to use a back-reference to sub-expression 1which is escaped as\1.

string:

something.min.js
min.js
1234.js
submin.js
file.js
admin.js
script.min.js
gar.min.js
garmin.min.js
harmin.marmin.min.js
garmin.js

matched:

min.js
1234.js
submin.js
file.js
admin.js
garmin.js
l'L'l
  • 40,316
  • 6
  • 77
  • 124