I created a VBA programme that clears Excel cells of number sequences between delimiters. The problem I'm encountering is that the text from the first delimiter to the end of the string is erased if the string contains content between the delimiters "(" and "," On delimited numbers, the code I've provided below works perfectly.
I need to alter the Regex pattern so that if a letter or word is discovered within a delimiter, nothing should be done and the delimiters should be removed. If there are numbers, the delimiters and everything in between them should be removed.
Function RemoveTags(ByVal Value As String) As String
Dim rx As New RegExp
.Global = True
.Pattern = "\((.*\d)\)"
RemoveTags = WorksheetFunction.Trim(rx.Replace(Value, ""))
This one is a good one.
Inputs: Put a stop to Rugby's foul school leader (5,2,3,4)
OutPut: Put a stop to Rugby's foul school leader
With the pattern: "\((.*\d)\)"
Input: Put a (stop to Rugby's) foul school leader (5,2,3,4)
Output: Put a
The above should be: Put a (stop to Rugby's) foul school leader
I have tried adding "\W" and other things to the pattern and have had no luck. I also have been using the regex expressions emulator at https://regexr.com/3hmb6