3

I have a big textfile with multiple paths like the following examples. The paths are always different. I'm looking for a regex (find and replace) in Notepad++ to replace the second-last "/" with "/;".

Example:

/testNAS/questions/ask/test/example/picture.png

After Replacing:

/testNAS/questions/ask/test/;example/picture.png

I tried with the regular expression /(?=[^/]*$) but this only marks the last slash.

Can anyone help me please?

syslog
  • 33
  • 4

4 Answers4

2

With your shown samples only, you could try following regex.

find what: ^(/[^/]*/[^/]*/[^/]*/[^/]*/)(.*)$

Replace with: $1;$2

Online Demo for above regex

Explanation: Adding detailed explanation for above regex.

^(                           ##Matching from starting of value in 1st capturing group.
  /[^/]*/[^/]*/[^/]*/[^/]*/  ##Matching / followed by till next occurrence of / doing this 4 times total in here.
)                            ##Closing 1st capturing group here.
(.*)$                        ##Creating 2nd capturing group which has rest of the values here.
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
2

You can use

^.*/\K[^/\r\n]*/[^/\r\n]*$
  • .*/ Match the last occurrence of /
  • \K Forget what is matched until so far
  • [^/\r\n]*/[^/\r\n]* Backtrack to match one occurrence of / using a negated character class matching any char other than a forward slach or a newline
  • $ End of string

And replace with a semicolon and the full match using ;$0

Regex demo

enter image description here

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
1

You can use

/(?=[^/\v]*/[^/\v]*$)

Replace with $0;. See the regex demo.

Details

  • / - a slash
  • (?=[^/\v]*/[^/\v]*$) - a positive lookahead that requires zero or more chars other than / and vertical whitespace, / and again zero or more chars other than / and vertical whitespace at the end of a line.

The $0; replacement pattern inserts the whole match value ($0) and then a ; char in place of a match.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
1

Try this, if you want to replace the fifth number slash, in your case the second-last from right to left..
Find what: ^(.*?\K/){5}
Replace with: /;

Haji Rahmatullah
  • 390
  • 1
  • 2
  • 11