Removing specific space

A swapping-ground for Regular Expression syntax

Removing specific space

Postby Sportif » Thu Jan 10, 2019 12:18 am

Hello,

I have a few hundred files to mange. Most need to be renamed.

Example (current):
Alan H 1.pdf
Sarah P 1.pdf
Sarah P 2.pdf
Extremelylongname A.pdf

Example (goal): I simply want to remove the space before the number while ignoring the files that do not include a number.
Alan H1.pdf
Sarah P1.pdf
Sarah P2.pdf
Extremelylongname A.pdf

All files include a first name followed by an initial, but not necessarily a numerical value (as shown above).

I haven't worked with regex in more then 10 years. Everything I come up with wipes the entire name, removes all spaces, or does nothing at all. I tried editing code from similar post and fail to get it right.

Thanks in advance to anyone that can and does provide a working solution.
Sportif
 
Posts: 3
Joined: Thu Jan 10, 2019 12:04 am

Re: Removing specific space

Postby Admin » Thu Jan 10, 2019 12:39 am

Hi, if you have a commercial license is very easy to do with Javascript, because you can just set it to remove second last char.
With RegEx you need to match a string with space and a char after, then a space, and then a char and rebuild without second match (the second space).
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Removing specific space

Postby therube » Thu Jan 10, 2019 1:59 pm

Would this do it?


1:RegEx
Code: Select all
Match:  (^.*) (\d*$)
Replace:  \1\2
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm


Return to Regular Expressions