Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expressions help 1

Status
Not open for further replies.

RobSchultz

Programmer
Jun 1, 2000
444
US
I'm trying to code an app that will read in a line of an ini file and pull out parameters.

The .ini would look similar to this:
Code:
[parameters]
T1 = [[parameter 1]][[parameter 2]][[parameter 3]]

The regular expression needs to be able to create a match collection that matches the groups of [[...]] into separate items.

The best I've been able to do (which isn't much) is with the pattern "\[\[(.*)\]\]". This returns a single match (yes, Global is on).

Help will be greatly appreciated,
Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Try

[tt]
Private Sub Command1_Click()
Dim sLine As String
Dim oReg As RegExp
Dim oMatches As MatchCollection
Dim oMatch As Match

sLine = "T1 = [[parameter 1]][[parameter 2]][[parameter 3]]"

Set oReg = New RegExp
With oReg
.Global = True
.Pattern = "\[\[[^\[\]]*\]\]"
Set oMatches = .Execute(sLine)
End With
Set oReg = Nothing

For Each oMatch In oMatches
Debug.Print oMatch.Value
Next oMatch
Set oMatch = Nothing
Set oMatches = Nothing
End Sub

[/tt]

I got

[[parameter 1]]
[[parameter 2]]
[[parameter 3]]
 
Thanks for the post back. I'll give it a try when I get to work on Monday.

Thanks, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Thanks Justin! :-D

That really did the trick. The NOT [ and NOT ] was the secret.

Thanks again, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top