Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This pattern should do what you need:
- <a\b([^>"']|"[^"]*"|'[^']*')+class="changed-by">.*?<\/a>
- I tested the pattern here:
- https://regex101.com/r/IyL5JR/2/
- To use this in VBA you'll probably need to escape the " characters by replacing each one with ""
- Based on some example code from here:
- https://stackoverflow.com/questions/22542834/how-to-use-regular-expressions-regex-in-microsoft-excel-both-in-cell-and-loops
- You could create a function to use from your Excel cells like this:
- Function simpleCellRegex(Myrange As Range) As String
- Dim regEx As New RegExp
- Dim strPattern As String
- Dim strInput As String
- Dim strReplace As String
- strPattern = "<a\b([^>""']|""[^""]*""|'[^']*')+class=""changed-by"">.*?<\/a>"
- If strPattern <> "" Then
- strInput = Myrange.Value
- strReplace = ""
- With regEx
- .Global = True
- .MultiLine = True
- .IgnoreCase = False
- .Pattern = strPattern
- End With
- If regEx.test(strInput) Then
- simpleCellRegex = regEx.Replace(strInput, strReplace)
- Else
- simpleCellRegex = strInput
- End If
- End If
- End Function
- You would use it by putting a formula in a cell like this:
- =simpleCellRegex(A1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement