Fellow members,
I have to parse data from a .txt file generated by an application. (line-by-line)
Unfortunately, it does not have a strict structure like .xml so I have to check
if it satisfies a particular pattern - thus I chose to use a regular expression.
The pattern is (pseudo):
(The characters IP (a space) (An ip address) (a space)
(The characters MAC (a space) (a mac address *** either a mac address OR the word 'unspecified') (a space)
(The characters Host Name (a space) (computer name *** follows active dir rules IE: min 2 characters max 24 - min i need)
(a space)
(Line break)
Examples that satisfy the pattern: * ips/macs masked for obvious reasons (those patterns seem to work)..problem seems to be with host name
IP: 127.0.0.57 MAC: 00:00:00:00:0C1 Host Name: Foobar-12345
IP: 127.0.0.58 MAC: unspecified Host Name: Foobar-12345678
IP: 127.0.0.59 MAC: unspecified Host Name: unspecified
Here is a pattern i tried to use...it works for the most part, however, it does not pick all badly generated output
IP: \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} MAC: (((?\d{1,2}|[a-fA-F]{1,2}){2})(?::|-*)){6})|(unspecified) Host Name: \w
Examples picked out by the above regex pattern:
1.(Bad ip address) IP: 1277.0.0.139 MAC: 00:00:00:a0:0B:50 Host Name: ABCDEFGHIJKL
2.(Bad ip address) IP: 127.0.0..52 MAC: 00:24:21:84:1E:B4 Host Name: MNBVCXZASDDR
3.(Bad ip chars) IP:: 127.0.0.23 MAC: 00:24:21:7B:AA:99 Host Name: HGFDRTHUIKJHG
3. (Bad mac address) IP: 127.0.0.51 MAC: 00:00::00:0F:0B:AD Host Name: GHIOPTREDCGM
4. (Bad mac chars) IP: 127.0.0.12 MMAC: 00:1F:0C:14:24:02 Host Name: JTRESWQRAFSS
Examples NOT picked out by the expression:
1. (Bad host chars) IP: 127.0.0.139 MAC: 00:00:00:a0:0B:50 Host Namee: ABCDEFGHIJKL
2. (Bad host chars) IP: 127.0.0.139 MAC: 00:00:00:a0:0B:50 Hosst Name: ABUUUHIJKL
note that i did not add a \n in the expression as it did not work but the lines end with a vbcrlf...same
with trying to ensure the min maximum charaters match like: w\{1,24} \n....this may let more get by
if one could help with getting ONLY the (pseudo) pattern to get by ...it would greatly be appreciated
Thanks!
I have to parse data from a .txt file generated by an application. (line-by-line)
Unfortunately, it does not have a strict structure like .xml so I have to check
if it satisfies a particular pattern - thus I chose to use a regular expression.
The pattern is (pseudo):
(The characters IP (a space) (An ip address) (a space)
(The characters MAC (a space) (a mac address *** either a mac address OR the word 'unspecified') (a space)
(The characters Host Name (a space) (computer name *** follows active dir rules IE: min 2 characters max 24 - min i need)
(a space)
(Line break)
Examples that satisfy the pattern: * ips/macs masked for obvious reasons (those patterns seem to work)..problem seems to be with host name
IP: 127.0.0.57 MAC: 00:00:00:00:0C1 Host Name: Foobar-12345
IP: 127.0.0.58 MAC: unspecified Host Name: Foobar-12345678
IP: 127.0.0.59 MAC: unspecified Host Name: unspecified
Here is a pattern i tried to use...it works for the most part, however, it does not pick all badly generated output
IP: \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} MAC: (((?\d{1,2}|[a-fA-F]{1,2}){2})(?::|-*)){6})|(unspecified) Host Name: \w
Examples picked out by the above regex pattern:
1.(Bad ip address) IP: 1277.0.0.139 MAC: 00:00:00:a0:0B:50 Host Name: ABCDEFGHIJKL
2.(Bad ip address) IP: 127.0.0..52 MAC: 00:24:21:84:1E:B4 Host Name: MNBVCXZASDDR
3.(Bad ip chars) IP:: 127.0.0.23 MAC: 00:24:21:7B:AA:99 Host Name: HGFDRTHUIKJHG
3. (Bad mac address) IP: 127.0.0.51 MAC: 00:00::00:0F:0B:AD Host Name: GHIOPTREDCGM
4. (Bad mac chars) IP: 127.0.0.12 MMAC: 00:1F:0C:14:24:02 Host Name: JTRESWQRAFSS
Examples NOT picked out by the expression:
1. (Bad host chars) IP: 127.0.0.139 MAC: 00:00:00:a0:0B:50 Host Namee: ABCDEFGHIJKL
2. (Bad host chars) IP: 127.0.0.139 MAC: 00:00:00:a0:0B:50 Hosst Name: ABUUUHIJKL
note that i did not add a \n in the expression as it did not work but the lines end with a vbcrlf...same
with trying to ensure the min maximum charaters match like: w\{1,24} \n....this may let more get by
if one could help with getting ONLY the (pseudo) pattern to get by ...it would greatly be appreciated
Thanks!