I'm currently using VBA and regex test an update i need to do with one of my fields.
My current SQL update is like this:
UPDATE Product SET Product.[Short description test] = MyRegexReplace(Product.[Short description], "[\(]+[A-z0-9\/]+[\)]", "");
As you can see the regex I'm using is [\(]+[A-z0-9\/]+[\)]
and replacing it with nothing.
The VBA script i am using is as below (I am using the reference Microsoft VBScript Regular Expressions 5.5):
Option Compare Database
Option Explicit
Public Function MyRegexReplace( _
originalText As Variant, _
regexPattern As String, _
replaceText As String) As Variant
' VBA Project Reference required:
' Microsoft VBScript Regular Expressions 5.5
Dim rtn As Variant
Dim objRegExp As RegExp, objMatch As Match, colMatches As MatchCollection
rtn = originalText
If Not IsNull(rtn) Then
Set objRegExp = New RegExp
objRegExp.pattern = regexPattern
Set colMatches = objRegExp.Execute(originalText)
For Each objMatch In colMatches
rtn = _
Left(rtn, objMatch.FirstIndex) & _
replaceText & _
Mid(rtn, objMatch.FirstIndex + objMatch.Length + 1)
Next
Set objMatch = Nothing
Set colMatches = Nothing
Set objRegExp = Nothing
End If
MyRegexReplace = rtn
End Function
My Problem is that most of the strings i am replacing it works fine on. As the aim is to remove anything in and including the curly brackets.
The issue is that on some longer string such as:
This is a test string [10876DB] =589+608+612= (P17/S)
it changes the string to:
This is a test string [10876DB] =589+608
Now i'm pretty sure that this is because my regular expression is matching things that it should not be matching and replacing them with nothing.
I have also tried this (which i have taken and edited from this post Regex: delete contents of square brackets):
\((?:[^\(\)]++|(?0))*+)
However, this just brings up an error. Can anyone advise on anything that may help me with this situation?
Thank you in advance.