regex for dir>print.txt -> Notepad++ -> oldname|newname pair

A swapping-ground for Regular Expression syntax

regex for dir>print.txt -> Notepad++ -> oldname|newname pair

Postby ffush » Fri Nov 21, 2014 9:43 am

Hi. I am looking to use regexes in Notepad++ to make oldname|newname pairs to Use in Bulk Rename Utility > File >Import Rename-Pairs.

So far I've got

Notepad++ > Search > Replace (with "Regular Expression" button selected)
Find what :
Code: Select all
\b[a-zA-Z0-9. ].*

Replace with :
Code: Select all

Which gives oldname|newname pairs which I can edit in Notepad++ using it's text editing capacities.

(And then when I've edited new file names that I like I save the file and use it in "Import Rename-Pairs".)

(I see on this forum I can also use a spreadsheet to make the pairs. Which is useful to know.)

Has anyone with greater regex knowledge got input on the limitations of the two regexes I'm using or suggestions on how they could be improved?
Posts: 1
Joined: Fri Nov 21, 2014 2:26 am

Re: regex for dir>print.txt -> Notepad++ -> oldname|newname pair

Postby Stefan » Fri Nov 21, 2014 12:33 pm

Hi and welcome.

You could use the more simpler form:

Notepad++ > Search > Replace
Find: .+
Repl: $0\|$0
[X]RegEx [_]. matches newline

The dot will match on ONE piece of any sign, the multiplicator + will match greedy (till the end) one-or-more of the expression on the left.

See the first post of this sub forum for more about.

- - -

Also you could do that with your DOS DIR command too, in one go:

X:\your\path\here> for /f "tokens=*" %F in ('  dir /b *.jpg  ') Do @ECHO %F^|%F > "X:\your path here\_Result.txt"

^ is here for DOS what \ is for regex, the escape sign.
And, for use in batch file, double the %-signs.

My example use:
Code: Select all
h:\a\TOOLS\Notepad++>for /f "tokens=*" %F in ('dir /b *.*') Do @ECHO %F^|%F

Edited to clarify some things.
Last edited by Stefan on Wed Dec 10, 2014 8:42 am, edited 1 time in total.
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: regex for dir>print.txt -> Notepad++ -> oldname|newname pair

Postby TheRegExpMaster » Tue Dec 09, 2014 10:40 pm

Stef, you're a pro !
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm

Return to Regular Expressions