#1 2015-04-07 08:23

crane
Member
Registered: 2015-04-07
Posts: 2

Replace underscore between numbers with dots

Example:
"file_name_v20_6_5_some_text.txt" to "file_name_v20.6.5_some_text.txt"

I tried the following regex replace but it fails:
(\d)_(\d)
$1.$2


Thanks

Last edited by crane (2015-04-07 12:42)

Offline

#2 2015-04-07 18:13

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Replace underscore between numbers with dots

Hi crane  and welcome.


This is because the regex engine didn't find another "(\d)_(\d)" match after the "20_6", there only is "_5_some_text.txt" remaining.
This would be different for a file name like "file_name_v20_6_some_6_5_text.txt"



The simplest solution for you is to duplicate the rule (right click the rule and chose 'Duplicate Rule')
One is for the  "20_6" and the other for the "6_5" part in a second pass.

1) RegEx: Replace expression "(\d)_(\d)" with "$1.$2" (skip extension)
2) RegEx: Replace expression "(\d)_(\d)" with "$1.$2" (skip extension)



- - -

Another solution, depending on the file names, would this single RegEx rule:

1) RegEx: Replace expression "_(\d)" with ".$1" (skip extension)



.

Last edited by Stefan (2015-04-07 18:14)


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2015-04-07 23:01

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,479

Re: Replace underscore between numbers with dots

Also, this handy PascalScript will do the job.

It will work for any number of sets of digits, no need to duplicate the rule.

var
  I: Integer;
begin
  for I := 2 to Length(FileName) - 1 do
    if FileName[i] = '_' then
      if IsWideCharDigit(FileName[I-1]) then
        if IsWideCharDigit(FileName[I+1]) then
          FileName[i] := '.';
end.

Offline

#4 2015-04-08 05:07

crane
Member
Registered: 2015-04-07
Posts: 2

Re: Replace underscore between numbers with dots

Pascal script is working fine.

Thanks smile

Offline

Board footer

Powered by FluxBB