我有一个从管理不善的旧数据库导入的非标准化字符串的大列表(一个包含一个字段的表)。我需要提取在每个字符串中恰好出现一次的一位数(由空格包围)(尽管字符串有时也有其他多位数)。例如,从以下字符串:
"Quality Assurance File System And Records Retention Johnson, R.M. 004 4 2999 ss/ds/free ReviewMo = Aug Effective 1/31/2012 FileOpen-?"
我想拉数字4
(或字符串中 4 的位置,即 71)
我可以用
WHERE rsLegacyList.F1 LIKE "* # *"
在select
语句中查找每个字符串是否有一个单独的数字,从而过滤我的列表。但它并没有告诉我数字在哪里,所以我可以提取数字本身(使用mid()
函数)并开始对列表进行排序。目标是使用该数字本身创建第二个字段,作为对第一个字段中较大字符串进行排序的方法。
有没有办法Instr()
与正则表达式一起使用来查找正则表达式在较大字符串中出现的位置?就像是
intMarkerLocation = instr(rsLegacyList.F1, Like "* # *")
但这真的有效吗?
我感谢任何完全避免该问题的建议或解决方法。
@Lee Mac,我做了一个RegExFindStringIndex
如下所示的函数:
Public Function RegExFindStringIndex(strToSearch As String, strPatternToMatch As String) As Integer
Dim regex As RegExp
Dim Matching As Match
Set regex = New RegExp
With regex
.MultiLine = False
.Global = True
.IgnoreCase = False
.Pattern = strPatternToMatch
Matching = .Execute(strToSearch)
RegExFindStringIndex = Matching.FirstIndex
End With
Set regex = Nothing
Set Matching = Nothing
End Function
但它给了我一个错误Invalid use of property at lineMatching = .Execute(strToSearch)