Reputation: 2265
My aim is to turn something like this:
src/com/company/folder/anotherfolder/manyfolders/filename.java
into this:
a few words com.company.folder.anotherfolder.manyfolders filename "description"
I've got it mostly to work with the following find and replace:
Find: (.*?)/(.*?)/(.*?)/(.*?)/(.*?)/(.*?)/(.*?)/(.*?)/(.*?)(\..*)
Replace: a few words $2\.$3\.$4\.$5\.$6\.$7\.$8\040$9\040"description"
Which works okay, however I may have different number of folders, so it won't work in that case.
How can I make it so that it works for any number of folders?
Upvotes: 0
Views: 434
Reputation: 71598
You are carrying out two distinct processes here:
/
by .
This is not possible with a single regex and if you still want to do it with the find/replace function of notepad++, you will need to do two replaces. I suggest the below replaces:
Replace /
by .
(no need for regex here, but if you have /
you don't want to replace, then it becomes more complex and you might to use a regex like (?:(?!^)\G|)\K/(?=[^.\r\n]*\.)
for the find and .
for the replace).
Regex replace of
[^.\r\n]+\.((?:[^.\r\n]+\.)+[^.\r\n]+)\.([^.\r\n]+)\.[^.\r\n]+
And replace with
a few words $1 $2 "description"
I am using this regex with the assumptions that folder and filenames can contain spaces and occupy a full line.
Upvotes: 1
Reputation: 179707
Consider using a few regexes in a row:
Convert slashes
/
=>
.
Convert the rest
([a-zA-Z0-9\.]+)\.(\w+)\.java
=>
a few words $1 $2 "description"
Upvotes: 1
Reputation: 7511
You'd need to repeat on the /
character - have you tried something like:
((.*)/)(.*)
Upvotes: 0