Remove all letters from specific word except the first

Advanced Renamer forum
#1 : 25/05-22 17:36
david mcgowan
Posts: 3
I have a load of files named

Firstname Secondname_001
Firstname Secondname_002

and i want them to be

Firstname S_001

how can i specify to remove everything either 2 characters after the space or from the second character of word 2
#2 : 26/05-22 07:41
David Lee
Posts: 1125
Try Remove pattern...

Pattern: [^ ]* \w\K[^_]*
Use regular expressions

Edit....

More simply...

Pattern " \w\K[^_]*"
(note: pattern starts with space)

edited: 26/05-22 08:56
#3 : 26/05-22 18:06
david mcgowan
Posts: 3
Reply to #2:
oh i see... you need to include the caret to signify the character.....

lol, i was so close.

and what does the K do?
#4 : 26/05-22 23:59
David Lee
Posts: 1125
Reply to #3:

"^" means "NOT"
So [^xyz] matches any character not listed (ie NOT x,y or z)

The metacharacter \K is an instruction not to include the preceding matched characters in the preceding match.

Thus the regex "[^ ]* \w\K" must match a string of any number of non-space characters followed by a space and a single word character but the matched characters are not included in the final text to be removed.

The remainder of the regex, "[^_]*", then matches any characters until an underscore is encountered - and this string is removed.

edited: 27/05-22 05:04