Advertisement
Guest User

tmpregex

a guest
Sep 19th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. This pattern should do what you need:
  2. <a\b([^>"']|"[^"]*"|'[^']*')+class="changed-by">.*?<\/a>
  3.  
  4. I tested the pattern here:
  5. https://regex101.com/r/IyL5JR/2/
  6.  
  7. To use this in VBA you'll probably need to escape the " characters by replacing each one with ""
  8.  
  9. Based on some example code from here:
  10. https://stackoverflow.com/questions/22542834/how-to-use-regular-expressions-regex-in-microsoft-excel-both-in-cell-and-loops
  11.  
  12. You could create a function to use from your Excel cells like this:
  13.  
  14. Function simpleCellRegex(Myrange As Range) As String
  15. Dim regEx As New RegExp
  16. Dim strPattern As String
  17. Dim strInput As String
  18. Dim strReplace As String
  19.  
  20. strPattern = "<a\b([^>""']|""[^""]*""|'[^']*')+class=""changed-by"">.*?<\/a>"
  21.  
  22. If strPattern <> "" Then
  23. strInput = Myrange.Value
  24. strReplace = ""
  25.  
  26. With regEx
  27. .Global = True
  28. .MultiLine = True
  29. .IgnoreCase = False
  30. .Pattern = strPattern
  31. End With
  32.  
  33. If regEx.test(strInput) Then
  34. simpleCellRegex = regEx.Replace(strInput, strReplace)
  35. Else
  36. simpleCellRegex = strInput
  37. End If
  38. End If
  39. End Function
  40.  
  41. You would use it by putting a formula in a cell like this:
  42. =simpleCellRegex(A1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement