Replace all characters except the last one

Advanced Renamer forum
#1 : 03/08-22 00:13
Baso
Posts: 4
Hi, I have a lot of files like this;

Vialidad_Nacional_1.jpg
Vialidad_Nacional_2.jpg
Vialidad_Nacional_3.jpg
England_20_Pound Sterling note 1999_1.jpg
England_20_Pound Sterling note 1999_2.jpg

And this is what I'm trying to do:

Vialidad Nacional_1.jpg
Vialidad Nacional_2.jpg
Vialidad Nacional_3.jpg
England 20_Pound Sterling note 1999_1.jpg
England 20_Pound Sterling note 1999_2.jpg

The idea is to replace all underscores with spaces except the last one. I'm dealing with RegEx but I cannot find the way.
I'll appreciate any help.
Thanks.

edited: 03/08-22 17:53
#2 : 04/08-22 11:04
David Lee
Posts: 1125
Use a "Lookahead" to match only an underscore if it is not followed by a string containing another one.

Replace: _(?=[^_]*_)
with: <space>
Use regular expressions

See https://www.regular-expressions.info/lookaround. html
but note that Lookbehind is not supported in Perl Compatible Regex.

edited: 04/08-22 12:03
#3 : 04/08-22 19:13
Baso
Posts: 4
Reply to #2:

Thank you very much David! That worked!

Also, the link you provided, explains Lookahead in detail (I couldn't find in this page in support section).