I am trying to search for all occurrences of doubles in a long chunk of text. the text represents the description of multiple defects in a system. The doubles I am looking for are depths that are normally in the text multiple times as "n.nnnW X n.nnnL X n.nnnD". The n.nnn
is normally 0.017D
(example) but I want to account for 5.567D
if that ever comes up.
The problem is that there are also occurrences of the terms within 1.5d of
and also a .015dia
. Case for the letters in these are also varied some are all caps and some are all lowercase. The text sometimes also has a space between the number and the "d" and sometimes spells out the word "deep" or "depth" like this: 0.017 deep
.
I need the values to be extracted as doubles eventually so I can do math on them.
I have the following regexp pattern: [.](?:\d*\.)?\d+(\s?)[dD](?!ia|IA)
This pattern seems to find all the things I need and even eliminates the diameters that are spelled out as n.nnndia
or n.nnnDIA
. The thing the pattern DOES NOT catch is the within 1.5d of
text.
After some light research I noted that in VBA the lookbehind code is NOT supported; and even so, I was never able to get the lookbehind pattern to work anyhow (using Regex101).
Here is my Access VBA code to illustrate how I am doing it. The r EXP(0)
value is my pattern above.
Set rs2 = CurrentDb.OpenRecordset("SELECT * FROM [NCR_RawImport-TEXT] WHERE " & skinTermSQL, dbOpenSnapshot)
'rEXP(0) = "[.](?:\d*\.)?\d+(\s?)[dD](?!ia|IA)"
tVAL = (CDbl(Me.cmbGDepth.Value) / 1000)
Do While Not rs2.EOF
found = False
Set regEXP1 = CreateObject("VBScript.RegExp")
regEXP1.IgnoreCase = True
regEXP1.Global = True
For i = 0 To rEXPIndx - 1
regEXP1.Pattern = rEXP(i)
Set Matches = regEXP1.Execute(rs2.NARR_TXT)
For Each Match In Matches
aVAL = CDbl(Trim(Replace(Replace(UCase(Match.Value), " D", ""), "D", ""))) 'convert matched value to a double.
If (aVAL >= tVAL) Then
found = True
End If
Next
Set Matches = Nothing
Next i
Set regEXP1 = Nothing
If (found) Then
strSql = "UPDATE [NCR_FinalData] SET [NCR_FinalData].SRCH = [NCR_FinalData].SRCH & 'G' WHERE [NCR_FinalData].SRCH Not Like '*G*' AND [NCR_FinalData].NC_KEY = '" & rs2.NC_KEY & "';"
Call writeLog("cmdUpdateNCRs: " & strSql)
DoCmd.RunSQL strSql
End If
rs2.MoveNext
Loop
Set rs2 = Nothing