how to search for numbers and reverse them

后端 未结 1 1930
慢半拍i
慢半拍i 2021-01-29 15:31

sorry about the title, but the stupid thing did not accept anything. I am triyng to do this

Dim myString, myResult
myString = \"Hello World! 1234 Hello World! 43         


        
相关标签:
1条回答
  • 2021-01-29 16:12

    You can do this using a replacement function:

    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"))
    

    Output:

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

    Just calling re.Replace(s, StrReverse("$1")) won't work, because in this statement, StrReverse reverses the string "$1" before re.Replace() is called.

    0 讨论(0)
提交回复
热议问题