1

OS: Windows 10 Tool: PowerRename

I need to remove the # symbol and the number in a file name IE:

ABC 2020 Sec. Fund - 2021 - # 1 Doe, John.pdf

to

Doe, John - ABC 2020 Sec. Fund - 2021.pdf

Using this expression:|

/(^[^#]*)-(.*$)

And this substitution:

$2 $1

I get the following:

ABC 2020 Sec. Fund - 2021 - # 1 Doe, John.pdf

Becomes

# 1 Doe, John ABC 2020 Sec. Fund - 2021.pdf 

There are multiple of these files that have to be renamed.

I need to make sure everything before the last name is removed. Everytime I add to this expression it breaks. I am not sure what I am missing.

0

2 Answers 2

2

I propose the following Regex :

(.*) - ([0-9]+) - # [0-9]+ (.*).pdf

With the following substitution pattern :

$3 - $1 - $2 .pdf

Explanation:

(.*) - match all char until the first -. The char before - are caught in first group

([0-9]+) Get all number between the first and the second - and catch it in the second group

# [0-9]+ (.*).pdf Get all char between the symbol # followed by one or several number, and .pdf, and catch it in the third group

Check here :

https://regex101.com/r/Fx5R6L/1

4
  • This looks like it works. I messed up and Missed something in the line though: ABC 2020 Sec. Fund - 2021 M1 - # 1 Doe, John.pdf Forgot the Schedule form name I am reading the explanation. Is there an entry that allows to do number and character like 0-9,a-z Commented Sep 13, 2022 at 20:27
  • I am also confused as to why the first ([0-9]+) has the (+) but the 2ns does not Commented Sep 13, 2022 at 20:29
  • [0-9a-zA-Z] match number and character.
    – S. Brottes
    Commented Sep 13, 2022 at 20:30
  • Answer edited to add more explanation
    – S. Brottes
    Commented Sep 13, 2022 at 20:35
1

So I need to add a "4th" set for the addition of the form type:

K1, M1, F3, ECT

ABC 2020 Sec. Fund - 2021 K1 - # 1 Doe, John.pdf

IE: (.?) - ([0-9]+) ([0-9a-zA-Z]+) - # [0-9]+ (.?).pdf

Sub: $4 $2 $3 - $1

Which would change: ABC 2020 Targeted Sec. Fund - 2021 K1 - # 1 Doe, John.pdf Into Werner, Joseph K1 - 2021 ABC 2020 Targeted Sec. Fund

I think I get the feel for it you can separate each into its own group and excluding character by leaving them outside the any brackets.

@S. Brottes - epic explanation thank you.

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Sep 13, 2022 at 22:08

You must log in to answer this question.

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