I have a list of about 30,000 files (with paths) that need to be individually copied along with their folder structures. Unfortunately, the paths are very long and the file copy utilities that will handle this function require that I specify destination folders for each file, which means I need to remove the file name from each of the 30,000 lines, leaving the folder structure intact.

What I need to do is find a way through a regular expression replace in Notepad++ that will delete all of the data on each line of the document after the last backslash "\" on the line.



Desired Output:


Any ideas on how to format the expression to allow this? I've tried [^"\"]+$, but that appears to be invalid.

  • 3
    \\[^\\]*$ is not doing the trick ?
    – dvhh
    Dec 18, 2014 at 2:42
  • If you give more details about copies you are going to make, maybe somebody can help with Robocopy, it's got a lot of functions.
    – SΛLVΘ
    Nov 6, 2015 at 10:26

2 Answers 2


You can use a RegEx capture group (denoted by the round brackets) to capture all characters (.*) up to (and including) the slash (\\ - you need to 'escape' the slash with another slash), and also include the rest of the characters in the Regex match (the second .*), since we want to replace them as well.

Then Replace the whole line with the contents of (just) that capture group (\1).

So this works for me:

Find: (.*\\).*

Replace with: \1

Make sure ". matches new line" is disabled.

  • Used this to remove everything after last pipe and it worked perfectly! Find: (.*\|).* Replace: \1
    – Crimp
    Mar 30, 2023 at 20:46

I answered my own question, hope this helps someone else trying to robocopy a specific list of files to their original folder structure. Edit the list in Notepad++ and use the replace function (select 'Regular Expression') and use the following string:


Replace that with blank and you're good to go.

  • Can you expand on what that RegEx does exactly? Dec 16, 2014 at 21:36
  • 2
    Why the lookbehind? Try this \\[^\\]+$
    – nixda
    Dec 16, 2014 at 21:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .