Extracting parts of a string

GMMorris

Regular
Joined
Feb 28, 2004
Messages
61
Hi,

I have a string of this format:
Code:
[pwd=BlaBla][Play(c:\Jah.mp3)]

What you see above is actually two tags [pwd={something}] and [{command}({data})].

What I want is to extract the Password, the command and the Data using Regex, so I don't have to fiddle around with strings. So that I end up with 3 strings.
In the above example they would be thas:
Code:
string sPassword = "BlaBla";
string sCommand = "Play";
string sData = @"c:\Jah.mp3";

Anyone know how?
 
Use this regex:

Code:
((\[pwd=)(?<password>\w*)]\[(?<command>\w+)\((?<data>[^\(\)]*)\)])

then, in VB.NET
Code:
Dim rx as Regex = New Regex("((\[pwd=)(?<password>\w*)]\[(?<command>\w+)\((?<data>[^\(\)]*)\)])")
Dim m as Match = rx.Match("[pwd=BlaBla][Play(c:\Jah.mp3)]")
Dim sPassword as string = m.Groups("password").Value
Dim sCommand as string = m.Groups("command").Value
Dim sData as string = m.Groups("data").Value
 
Back
Top