T
The Cleaner
Ron, you posted this some time ago in a forum somewhere.
It lowercases and replaces anything that is not a letter or number with -.
All well and good... however, if there are two of the replaced items together the result is --.
So Ron""Ron becomes ron--ron.
Is it possible to add one last thing to the code below that will replace any multiple of hyphens -- --- ---- and so on with a single hyphen - ?
So ron--ron or ron---ron always becomes ron-ron ? One hyphen allowed only ever.
Thanks in advance!
Option Explicit
Function NonAlphaDash(str As String) As String
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "[^a-z0-9]"
NonAlphaDash = re.Replace(LCase(str), "-")
End Function
It lowercases and replaces anything that is not a letter or number with -.
All well and good... however, if there are two of the replaced items together the result is --.
So Ron""Ron becomes ron--ron.
Is it possible to add one last thing to the code below that will replace any multiple of hyphens -- --- ---- and so on with a single hyphen - ?
So ron--ron or ron---ron always becomes ron-ron ? One hyphen allowed only ever.
Thanks in advance!
Option Explicit
Function NonAlphaDash(str As String) As String
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "[^a-z0-9]"
NonAlphaDash = re.Replace(LCase(str), "-")
End Function