-3

对不起标题,但愚蠢的东西没有接受任何东西。我正在尝试这样做

Dim myString, myResult
myString = "Hello World! 1234 Hello World! 4321 Hello World! 6789"
Set myRegex = New RegExp
myRegex.Global = true
myRegex.IgnoreCase = true
myRegex.Pattern = "([0-9]+)"
myResult = myRegex.Replace(myString, StrReverse("$1"))

我希望所有数字都反转我希望字符串看起来像这样“Hello World!4321 Hello World!1234 Hello World!9876”但我得到的只是“1$”

谢谢 :-)

4

1 回答 1

2

您可以使用替换功能来做到这一点:

Function Reverse(m, pos, src)
  Reverse = StrReverse(m)
End Function

Set re = New RegExp
re.Pattern = "\d+"
re.Global = True

s = "Hello World! 1234 Hello World! 4321 Hello World! 6789"

WScript.Echo re.Replace(s, GetRef("Reverse"))

输出:

Hello World! 4321 Hello World! 1234 Hello World! 9876

仅仅调用re.Replace(s, StrReverse("$1"))是行不通的,因为在这个语句中,在调用StrReverse之前反转了字符串“$1” re.Replace()

于 2013-07-09T20:58:18.807 回答