Replace all characters except the last one
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.
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.
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.
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.
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).
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).