Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How in notepad++ find/replace text between slashes?

How to find the text between the second and fourth slashes in a path like /folder/subfolder-1/subfolder-2/subfolder-3? I’m trying to replace this with something like /folder/new-folder/subfolder-3.

The most important for me is to be able to find the part after the n-th slash.

I tried the regex /((.*?)/){3}, but it doesn’t work.

like image 748
MartiX Avatar asked Jan 17 '17 16:01

MartiX


2 Answers

Using Match resetter \K meta-character you are able to do it in a simpler way.

Find:

/.*?/\K(.*?/){2}

Replace with:

new-folder/
like image 98
revo Avatar answered Oct 20 '22 03:10

revo


One way you could to it is by using this string in the pattern to replace

(/.+?)(/.+?){2}(/\S+)

And use this one in your pattern to replace it with

$1/new-folder$3

From your string:

/folder/subfolder-1/subfolder-2/subfolder-3
  • (/.+?) will match /folder as $1

  • (/.+?){2} will match /subfolder-1/subfolder-2 as $2 (not used)

  • (/\S+) will match everything that isn't a space, in this case/subfolder-3 as $3

Leaving you room to insert your new-folder in-between.

like image 36
Sebastien Dufresne Avatar answered Oct 20 '22 03:10

Sebastien Dufresne