Script or Regexp Rename function

Discuss and share scripts and script files...
Post Reply
kluv
Posts: 35
Joined: 02 Mar 2011 13:23

Script or Regexp Rename function

Post by kluv »

Sometime ago I found a script or Regexp that, for all files selected, would delete numbers before a dash in a file name. I've tried finding it again but have had no luck.

Can anyone point me in the right direction or reproduce the formula for me?

The file format I used it for was: ex. 30046-file_name_222.ext. Where the unwanted characters would be 30046-.

Thank you for any help you can give me.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Script or Regexp Rename function

Post by Stefan »

Hi welcome!

Do you need an whole script or just the regex?

FROM:
30046-file_name_222.ext
TO:
file_name_222.ext
DO:
Match non-grouped all digits till and included an dash, then grouped the rest:
\d+-(.*) > $1

Using:
- select fiiles
- menu "File > Rename Special > RegExp Rename..."
- paste in \d+-(.*) > $1
- press [Preview...]

Explanation:
\d ==> match one digit
+ ==> match one-or-more of the last expression (here the \d)
- ==> match an dash
(.*) ==> match the rest and group this for reuse
" > " ==> XYplorers regexp delimiter
$1 ==> replace with what is matched in group #1


HTH? :D

---

Update
to match digits OR space till and including an dash:

FROM:
30046-file_name_222.ext
30 46-file_name_223.ext
TO:
file_name_222.ext
file_name_223.ext
DO:
(\d|\s)*-(.*) > $2


and to simply match all signs till and including first dash:
FROM:
ABC46-file_name_224.ext
_1 46-file-name_225.ext
TO:
file_name_224.ext
file-name_225.ext
DO:
(.*?)-(.*) > $2

kluv
Posts: 35
Joined: 02 Mar 2011 13:23

Re: Script or Regexp Rename function

Post by kluv »

That worked perfect. Thank you so much.

Post Reply