Hi
I have variations of the following type of string generated from a stat program:
Equation: (On 1 Row)
-------------------------------
DLOG(DEM_B_C_TRP(-3)/1000+1)*.01/(.01+.24947)+DLOG(DEM_B_C_VT(-1)/1000+1)*.35947/(.01+.24947)
I would like to pass a regex PATTERN to a VBA function such that the resultant
output would look like this:
(This output results in 3 rows)
DLOG(DEM_B_C_TRP(-3)/1000+1)*.01/(.01+.24947)
+
DLOG(DEM_B_C_VT(-1)/1000+1)*.35947/(.01+.24947)
==========================================
Whats important to *see* within the equation
is that there are
+ signs WITHIN () and
+ signs NOT within ()
and it is the + signs not within () that are the discrimenators
that identify each _segment_ of the overall equation.
==========================================
At present I am using the function below (found at a MS site)
but I am not certain it is the correct function to use.
More importantly, I just cannot figure out the correct pattern
to employ that deals with definitions above.
I have tried numerious patterns and my current one is
=msfind(A22,"(DLOG)+[^Z.*]+.*")
Bottom line - I just can't *see* the correct syntax. (This is the first
time I have tried RegEx)
Current Function:
Note: I realize the current function could NOT return multiple
rows but at this time I am trying to get it to just return
the 1st segment
'http://www.cs.cf.ac.uk/Dave/Internet/NEWS/regexp.html#simple
Function MSFind(pFindIn As String, pFindWhat As String)
'http://support.microsoft.com/kb/818802/en-us
'Create objects.
Dim oItem As Match
Dim colMatches As MatchCollection
Dim sReturn As String
'-------------------------
' Create a regular expression object.
'-------------------------
Dim R As New VBScript_RegExp_55.RegExp
'-------------------------
'Set the pattern by using the Pattern property.
' Set Case Insensitivity.
'Set global applicability.
'-------------------------
R.Pattern = pFindWhat
R.IgnoreCase = True
R.Global = True
'-------------------------
'Test whether the String can be compared.
'-------------------------
If (R.Test(pFindIn) = True) Then
'-------------------------
'Get the matches.
'-------------------------
Set colMatches = R.Execute(pFindIn) ' Execute search.
'-------------------------
'Get the matches.
'-------------------------
For Each oItem In colMatches ' Iterate Matches collection.
'sReturn = sReturn & "Match found at position "
sReturn = sReturn & "P:" & oItem.FirstIndex & Space(2)
sReturn = sReturn & "V:" & Space(1) & oItem.Value & Space(5)
Next
Else
sReturn = "String Matching Failed"
End If
'-------------------------
'-------------------------
MSFind = sReturn
End Function
regards
John
Bookmarks