sublimetext2 - Regex for converting file path to package/namespace -
given following file path:
/users/lawrence/myproject/some/very/interesting/code.scala
i generate following using single regex replace (the root can constant):
some.very.interesting
this purpose of generating snippet sublime text can automatically insert correct package/namespace header scala/java classes :)
sublime text uses following syntax regex replace patterns (aka 'substitutions'):
{input/regex/replace/flags}
hence why iterative approach cannot taken - has done in 1 pass! also, substitutions cannot nested :(
if know maximum number of nested folders.you can specify in regex.
for 1 3 nested folders
regex:/users/lawrence/myproject/(\w+)/?(\w+)?/?(\w+)?/[^/]+$
replace:$1.$2.$3
for 1 5 nested folders
regex:/users/lawrence/myproject/(\w+)/?(\w+)?/?(\w+)?/?(\w+)?/?(\w+)?/[^/]+$
replace:$1.$2.$3.$4.$5
given constraints thing can do
Comments
Post a Comment