gpt4 book ai didi

regex - 当数字用引号引起来时 VBScript 正则表达式替换

转载 作者:行者123 更新时间:2023-12-01 10:27:11 25 4
gpt4 key购买 nike

在 VBScript 中使用正则表达式,我需要用点替换引号 chr(34) 中的小数逗号

Input
20170927,Ford,,"6025,00",,"0,00",1,T
20170928,"Fiat, Opel",,"13587,17","13587,17",2,N

Output
20170927,Ford,,"6025.00",,"0.00",1,T
20170928,"Fiat, Opel",,"13587.17","13587.17",2,N

我试过下面的代码,但没有用。

Dim oRE,text
Set oRE = New RegExp
oRE.Global = True
oRE.Pattern = chr(34)+[0-9],[0-9]+chr(34)
oRE.Replace(text, Replace(text,",","."))

非常感谢。

最佳答案

试试下面的代码:

代码:

strTest = "20170928,""Fiat, Opel"",,""13587,17"",""13587,17"",2,N"    'Store the text to be tested in this variable
Set re = New RegExp
re.Global=True
re.Pattern = "(""\d*),(\d+"")"
Set objMatches = re.Execute(strTest)

For Each match In objMatches
strTest = Replace(strTest,match.Value,match.Submatches.Item(0)&"."&match.Submatches.Item(1))
Next

MsgBox strTest

输出:

enter image description here

使用正则表达式:

("\d*),(\d+")

Click here for Regex Demo

正则表达式解释:

  • ("\d*) - 匹配 " 后跟出现 0 次以上的数字。括号包含第 1 组中的整个部分。
  • , - 按字面匹配 ,
  • (\d+") - 匹配出现 1 次以上的数字后跟 "。括号包含第 2 组中的整个部分。

关于regex - 当数字用引号引起来时 VBScript 正则表达式替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46476349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com