Regex help : replace dots by spaces

I need some help to replace dots by spaces only if previous/next character is letter.

Directory.Opus. -> Directory Opus x86.txt

I assume you mean you only want the dots replaced by spaces if the dots are not between two digits. And also that you the file extension left alone (not changed from exe to txt).

If so, I'd use a 2 step renaming process to do this. The first removes all dots (periods) from the file name with the exception of the . before the file extension, while the second step replaces spaces with periods in between two digits. Button code follows.

<?xml version="1.0"?> <button display="both"> <label>Strip periods</label> <tip>Strips periods unless between two digits</tip> <icon1>84</icon1> <function type="normal"> <instruction>rename PATTERN=&quot;.&quot; TO=&quot; &quot; FINDREP</instruction> <instruction>@nodeselect</instruction> <instruction>rename PATTERN=&quot;(.*[0-9]) ([0-9].*)#&quot; TO=&quot;\1.\2&quot; REGEXP</instruction> </function> </button>

Use the following code in Script Mode

[code]@script vbscript
option explicit

Function Rename_GetNewName ( strFileName, strFullPath, fIsFolder, strOldName, ByRef strNewName )

Dim regex
Dim strExtension
Dim strNameOnly

' Create a RegExp object
Set regex = new RegExp
regex.IgnoreCase = True ' Ignore Case-sensitive matching.
regex.Global = True ' All matches will be replaced, not just the first match.

' If we're renaming a file then remove the extension from the end and save it for later.
If fIsFolder or 0 = InStr(strFileName,".") then
strExtension = ""
strNameOnly = strFileName
strExtension = Right(strFileName, Len(strFileName)-(InStrRev(strFileName,".")-1))
strNameOnly = Left(strFileName, InStrRev(strFileName,".")-1)
End If

' Renaming

' Replace Dots, except between numbers
regex.Pattern = "([^0-9]|[0-9]).([^0-9]| )" 'Example: Nero.v8.2.[Build.123].zip --> Nero v8.2 [Build 123].zip
strNameOnly = regex.Replace(strNameOnly, "$1 $2") '
strNameOnly = regex.Replace(strNameOnly, "$1 $2") 'repeat search from begining for losed rplaces
regex.Pattern = "([^0-9]).([0-9])" 'Example: BootCD.8.2.iso --> BootCD 8.2.iso
strNameOnly = regex.Replace(strNameOnly, "$1 $2")
strNameOnly = regex.Replace(strNameOnly, "$1 $2") 'repeat search from begining for losed rplaces

' Rejoin the name and extension (to lower case) and we're finished
strNewName = strNameOnly & LCase(strExtension)

End Function

Of course... grrrrrrr really borring, can't edit post !!

Thanks a lot, i try in one step with no success... but i'm curious, why it's not possible in one step ?

@NoDeselect Rename REGEXP PATTERN="(.*)(([^0-9])\.|()\.([^0-9]))(.*\..*)#" TO="\1\3 \4 \5\6"

You could do it in one line as Zippo showed, and searcher's script seems to do the trick as well. I just dashed off my suggestion quickly as I have a busy day today (I'm hitting the road shortly and won't be back until late tonight).

[quote="Zippo"]@NoDeselect Rename REGEXP PATTERN="(.*)(([^0-9])\.|()\.([^0-9]))(.*\..*)#" TO="\1\3 \4 \5\6"[/quote]

Neat! I didn't know you could refer to brackets-in-brackets like that with the regexp syntax. That will come in handy.

I think that expression has a problem, though. It adds two spaces instead of one.

This seems to fix it, but I have not really thought about all the potential cases so it might not be correct:

@NoDeselect Rename REGEXP PATTERN="(.*)(([^0-9])\.|()\.([^0-9]))(.*\..*)#" TO="\1\3 \4\5\6"

i.e. Just remove one of the spaces next to the \4 in the new name. It doesn't seem to matter which one you remove. (At least, not with AlbatorV's example filename. I have not tested it or thought about it extensively, as I said.)

Thanks Leo,

Obviously, two space characters aren't needed to solve the problem.

I've been a little farsighted at times recently.
I didn't see that there were two ' ' characters in my results.
I was also in a hurry as it was time for me to go to work.

Hence, a more elegant solution results. @NoDeselect Rename REGEXP PATTERN="(.*)(([^0-9])\.|\.([^0-9]))(.*\..*)#" TO="\1\3 \4\5"
Perhaps this isn't exactly what AlbatorV was looking for, but it is easy to modify this .

Many thanks guys... I'll never find this...
Regex is so powerfull, i need to learn more and more.

And here is another one.
This flanks '-' characters with a space character on each side if the space character does not already exist.
Additionally, multiple space characters are reduced to only one.

@NoDeselect Rename REGEXP PATTERN="(.*)(([^ ])(-)|(-)([^ ])| )(.*)#" TO="\1\5\3 \4\6\7"