By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,283 Members | 1,676 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,283 IT Pros & Developers. It's quick & easy.

Find All Instances of a Subpattern Using RegExp?

P: n/a
Using the Microsoft VBScript Regular Expressions 5.5 library in
MS-Access VBA 6.3.

I understand why the code below finds an occurance of the string "PC:
blah blah blah A: BBB aaa B: BBB bbb C: BBB ccc"" but I cannot think
how to make it find all such strings.

My two alternative kludges are;
- build up a pattern of subpatterns until the pattern will not match
- add some hard delimiter (unusual single character) and divide the
incoming document into sections first

Any help would be great.

Function bigregexp()
' Search all the words in a string
Dim re As New regexp, m As Match
Dim t As String, i As Integer
t = "jfk jfk jfk AAA PC:AAA junk A: AAA aaa B: AAA bbb C: AAA ccc
BBB " & _
"PC: BBB junk A: BBB aaa B: BBB bbb C: BBB ccc"
re.Pattern = "(PC:.*A:(.+)B:(.+)C:(.+))"
re.Global = True
For Each m In re.Execute(t)
For i = 0 To m.SubMatches.Count - 1
MsgBox ("Pattern: " & m.SubMatches(i))
Next i
Next
End Function

May 10 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Replacing the multi-character delimiter "PC:" with a single character
"#" seems to work like so;

Sub bigregexp()
' Search all the words in a string
Dim re As New RegExp, m As Match
Dim t As String, inpos As Integer
t = "jfk jfk jfk AAA PC:AAA junk A: AAA aaa B: AAA bbb C: AAA ccc
BBB " & _
"PC: BBB junk A: BBB aaa B: BBB bbb C: BBB ccc"
t = Replace(t, "PC:", "#", , , vbTextCompare)
re.Pattern = "#[^#]*A:([^#]+)B:([^#]+)C:([^#]+)"
re.Global = True
For Each m In re.Execute(t)
For i = 0 To m.SubMatches.Count - 1
MsgBox ("Pattern: " & m.SubMatches(i))
Next i
Next
End Sub

I wonder if there is another solution?

May 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.