How to replace the last space in a directory?

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
Oesie
Junior Member
Junior Member
Posts: 18
Joined: 2012-04-21, 07:58 UTC

How to replace the last space in a directory?

Post by *Oesie »

Is there a way to use the multi-rename tool to replace the last space in a directory?

Example

From:
This is a directory from 1988
I would like to replace the last space

To:
This is a directory from-1988
I would like to replace the last-space
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Search for: (.*) (.*)
Replace with: $1-$2
RegEx: Yes
Subst.: Yes
Oesie
Junior Member
Junior Member
Posts: 18
Joined: 2012-04-21, 07:58 UTC

Post by *Oesie »

MVV wrote:Search for: (.*) (.*)
Replace with: $1-$2
RegEx: Yes
Subst.: Yes
Brilliant, thanks! Couldn't have figured that out myself. Still don't know how the last space is found by the search pattern :-)
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Glad to help:)

It works simply. Regex uses greedy search mode by default, therefore first * finds as many characters as it can until the space (so it gets all previous spaces too). Second * just takes the rest, and braces define first and second subexpressions, which are used as parts or replace expression. You may read help topic about regex for more details.
User avatar
white
Power Member
Power Member
Posts: 6018
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Post by *white »

MVV wrote:Subst.: Yes
What good would that do?
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

white,
Maybe it is not necessary here, but it won't hurt.
User avatar
white
Power Member
Power Member
Posts: 6018
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Post by *white »

MVV wrote:Maybe it is not necessary here, but it won't hurt.
It's a lot more work. ;-)
Post Reply