I have a script that I want to use to format the following text:
My name is John Q. Smith- Jones.txt -> My name is John Q. Smith-Jones.txt
This is the code I have cobbled together. The part that's in bold are the Old Name New Name regex that works when directly doing a regex rename in Dopus, but the same regex doesn;'t work in my script. I can't figure out why.
'Fix hyphen following any character
regex.Pattern = "b(\w)- (\w)(.*)[/b]"
strNameOnly = regex.Replace(strNameOnly, "\1\2 - \3\4"
[code]@script vbscript
option explicit
Function Rename_GetNewName ( strFileName, strFullPath, fIsFolder, strOldName, ByRef strNewName )
Dim regex
Dim strWordArray
Dim strExtension
Dim strNameOnly
'Create a RegExp object. See http://msdn2.microsoft.com/en-us/library/ms974570.aspx
Set regex = new RegExp
regex.IgnoreCase = True ' Case-insensitive 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
else
strExtension = Right(strFileName, Len(strFileName)-(InStrRev(strFileName,".")-1))
strNameOnly = Left(strFileName, InStrRev(strFileName,".")-1)
end if
'Fix hyphen following any character
regex.Pattern = "(.)(\w)- (\w)(.)"
strNameOnly = regex.Replace(strNameOnly, "\1\2 - \3\4"
' Rejoin the name and extension (to lower case) and we're finished
strNewName = strNameOnly & LCase(strExtension)[/code]
End Function
Can anyone help? I'm sure it's obvious but I am still struggling to learn Regex as a non-programmer. I'm a network guy, LOL.
Scott
Sarasota, FL