使用VBScript 5.5 Regex,如何替换字符串,以便每4个字符后有一个空格?
我尝试了以下但不起作用:
Dim rex As New RegExp
rex.IgnoreCase = True
rex.Global = True
rex.Pattern = ".{4}"
Dim newString as String
newString = Trim$(rex.Replace(Trim$(inputString), "$0 "))
答案 0 :(得分:3)
你需要group()和更好的ref($ 1):
>> Set r = New RegExp
>> r.Global = True
>> r.Pattern = "(.{4})"
>> WScript.Echo r.Replace("1234567890123", "$1 ")
>>
1234 5678 9012 3
>>