Truncate filename

A swapping-ground for Regular Expression syntax

Truncate filename

Postby LeoL30 » Mon Dec 05, 2022 5:16 pm

I often rename a list of files (see Sample List below). I would like to remove the sequence of letters, numbers and hyphens + gigapixel (in Bold) at the end of the filename. When the filenames have the same sequence/pattern of characters I can use Remove (5) to remove 47 characters from the end. Job done. I now have files which can have names without the sequence. I tried a Simple RegExp but don't have enough knowledge to identify the part of the file name that has text of different lengths after "Prompt used - ". Is there a RegExp I can use to remove the sequence. Your assistance will be gratefully received. Thanks in advance for any help that can provided. Cheers

The closest I could get with my limited RegExp knowledge:
Match: %1 - %2-%3-%4-%5 %6 e.g. Prompt used - yacht rock band 0fc4134d-c8f5-4b33-8cd7-cac680e5f8c4 gigapixel.jpg
Replace: %1 %2 e.g. Prompt used - yacht rock band 0fc4134d.jpg :(


Sample List
Prompt used - radio chasis 77cb2221-48be-4944-b8c0-ae047ddfe47f gigapixel.jpg
Prompt used - volume control grip set to 11 f7d03837-9411-4ab2-8f8b-bbb0332ddf07 gigapixel.jpg
Prompt used - abstract composition in the style of suprematism.jpg
Prompt used - spin painting 12b54ae8-95da-4d79-a0bb-241d3c562ac1 gigapixel.jpg
Prompt used - radio chasis 81f014bd-3b8b-4bf5-890b-6a1bb4d2cd4e gigapixel.jpg
Prompt used - fly compound eye scanning electron microscope photograph.jpg
Prompt used - abstract composition in the style of constructivism.jpg
Prompt used - volume control set to 11 4aa4b609-20c7-490e-925d-683b53e33f39 gigapixel.jpg
Prompt used - example of a digital collage.jpg
LeoL30
 
Posts: 5
Joined: Mon Dec 05, 2022 4:37 pm

Re: Truncate filename

Postby LeoL30 » Mon Dec 05, 2022 6:12 pm

I think I have a RegExp that works but if anyone has a more elegant way of doing it I'd like to know the solution.

Code: Select all
Match: (.*) (.*)-(.*)-(.*)-(.*)-(.*) (.*)
Replace: \1
LeoL30
 
Posts: 5
Joined: Mon Dec 05, 2022 4:37 pm

Re: Truncate filename

Postby therube » Mon Dec 05, 2022 6:20 pm

I believe that may get it. Make sure it is correct:

1:RexEx, enable v2
Code: Select all
Match:  (.*) (.*\sgigapixel)
Replace:  \1

(Maybe someone could point out why that works, if it does?)
therube
 
Posts: 1319
Joined: Mon Jan 18, 2016 6:23 pm

Re: Truncate filename

Postby LeoL30 » Mon Dec 05, 2022 8:17 pm

@therube
Thanks, yes that works for me. Cheers
LeoL30
 
Posts: 5
Joined: Mon Dec 05, 2022 4:37 pm

Re: Truncate filename

Postby dec » Sun May 14, 2023 4:57 am

... i don't really understand RegEx syntax at all;

but would these solutions depend on there being the same number of segments in all the names? or not?
dec
 
Posts: 67
Joined: Thu Oct 14, 2021 6:31 am


Return to Regular Expressions


cron