Excel正則替換文本內容


 

犯了個失誤,在excel中下拉數據時不小心端口號自增了。大概上萬條數據,寫了個正則表達式,完美解決問題。

curl -X GET http://10.0.0.150:8090/xxx?param=3000001;

curl -X GET http://10.0.0.150:8090/xxx?param=3000001;
curl -X GET http://10.0.0.150:8091/xxx?param=3000001;

  

Private Sub RegExp_Replace()
 
    Dim RegExp As Object
    Dim SearchRange As Range, Cell As Range
    
    '此處定義正則表達式
    Set RegExp = CreateObject("vbscript.regexp")
    RegExp.Pattern = "150:.*/"
     
    '此處指定查找范圍
    Set SearchRange = ActiveSheet.Range("A1:A5000")
    
    '遍歷查找范圍內的單元格
    For Each Cell In SearchRange
        Set Matches = RegExp.Execute(Cell.Value)
        If Matches.Count >= 1 Then
            Set Match = Matches(0)
            Cell.Value = RegExp.Replace(Cell.Value, "150:8090/")
        End If
    Next
 
End Sub

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM