We help IT Professionals succeed at work.

Regex - Asp.net

I  want to get the values from the given string below
VMid , Name, DataStore, GuestOs

for ex.
vmid = 112
Name = SanalSunucu - MSN
Datastore = Datastore1
File = SanalSunucu - MSN/SanalSunucu - MSN.vmx
GuestOs = windows7Server64Guest

How should i get them ?
Vmid                Name                                                       File                                                Guest OS          Version   Annotation
112    SanalSunucu - MSN                [DataStore1] SanalSunucu - MSN/SanalSunucu - MSN.vmx                                 windows7Server64Guest   vmx-07
144    SanalSunucu - Uludas      [DataStore1] SanalSunucu - NevcanUluda+xZ8/SanalSunucu - Uludas_1.vmx          centos64Guest           vmx-07
16     SanalSunucu - SeyhmuzMSN         [DataStore1] SanalSunucu - SeyhmuzMSN/SanalSunucu - SeyhmuzMSN.vmx                   windows7Server64Guest   vmx-07
160    SanalSunucu - Sami               [DataStore1] SanalSunucu - Sami/SanalSunucu - Sami.vmx                               windows7Server64Guest   vmx-07
176    SanalSunucu - Database           [DataStore1] SanalSunucu - Database/SanalSunucu - Database.vmx                       windows7Server64Guest   vmx-07
192    SanalSunucu - bonusum.com        [DataStore1] SanalSunucu - bonusum.com/SanalSunucu - bonusum.com.vmx                 centos64Guest           vmx-07
208    SanalSunucu - EvrenTuran         [DataStore1] SanalSunucu - EvrenTuran/SanalSunucu - EvrenTuran.vmx                   centosGuest             vmx-07
224    SanalSunucu - MehmetKadir        [DataStore1] SanalSunucu - MehmetKadir/SanalSunucu - MehmetKadir.vmx                 centos64Guest           vmx-07
256    SanalSunucu - YemekMail          [DataStore1] SanalSunucu - YemekMail/SanalSunucu - YemekMail.vmx                     debian5_64Guest         vmx-07
288    SanalSunucu - Metin2             [DataStore1] SanalSunucu - Metin2/SanalSunucu - Metin2.vmx                           freebsdGuest            vmx-07
32     SanalSunucu - Ferhat             [DataStore1] SanalSunucu - Ferhat/SanalSunucu - Ferhat.vmx                           winLonghorn64Guest      vmx-07
336    SanalSunucu - Okan               [DataStore1] SanalSunucu - Okan/SanalSunucu - Okan.vmx                               winXPProGuest           vmx-07
48     SanalSunucu - Mikrotik           [DataStore1] SanalSunucu - Mikrotik/SanalSunucu - Mikrotik.vmx                       otherGuest              vmx-07
64     SanalSunucu - Seyhmuz            [DataStore1] SanalSuncu - Seyhmuz/SanalSuncu - Seyhmuz.vmx                           windows7Server64Guest   vmx-07
80     SanalSunucu - Salay ic Network   [DataStore1] SanalSunucu - Salay i+w6c- Netwo/SanalSunucu - Salay i+w6c- Netwo.vmx   winLonghorn64Guest      vmx-07
96     SanalSunucu - PRTG               [DataStore1] PRTC/SanalSunucu - PRTG.vmx                                             windows7Server64Guest   vmx-07

Open in new window

Comment
Watch Question

IT Guru
Most Valuable Expert 2011
Commented:
This seems to work for me in myregextester.com:

    Dim sourcestring as String = "replace with your source string"
    Dim re As Regex = New Regex("^(\d+)\s*([^[]*)\[([^\]]*)\]\s*(.*?)\s\s(\S+)",RegexOptions.Multiline)
    Dim mc as MatchCollection = re.Matches(sourcestring)
    Dim mIdx as Integer = 0
    For each m as Match in mc
      For groupIdx As Integer = 0 To m.Groups.Count - 1
        Console.WriteLine("[{0}][{1}] = {2}", mIdx, re.GetGroupNames(groupIdx), m.Groups(groupIdx).Value)
      Next
      mIdx=mIdx+1
    Next
Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:
Note that PHP is my language of choice, so I'll need to leave it to you (or another expert) to alter the code structure to something useful to you. The pattern should work for you though.

Author

Commented:
That only catched the lines not splitted as on the other question result is same

Author

Commented:
Same changes worked thnx