sirbounty
asked on
regex help
New to regexes, so I'd also like a brief explanation of the answer, but I'm looking for a regex that would match
SCSI Bus 0
SCSI Target 0 ..................(+) COMPAQ BF03685A35
Capacity ......................(+) 34,732 MBytes (71132000 Blocks)
Serial Number .................(+) 3HX14GZ300007402A8CA
Firmware Version ..............(+) HPB4
AND
SCSI Bus 0
SCSI Target 0 .................. COMPAQ BF03685A35
Capacity ...................... 34,732 MBytes (71132000 Blocks)
Serial Number ................. 3HX14GZ300007402A8CA
Firmware Version .............. HPB4
BUT NOT
SCSI Bus 0
SCSI Target 0 ..................(-) COMPAQ BF03685A35
Capacity ......................(-) 34,732 MBytes (71132000 Blocks)
Serial Number .................(-) 3HX14GZ300007402A8CA
Firmware Version ..............(-) HPB4
Obviously SCSI Bus 0 would be matched in all three - and that's fine, but I want to exclude lines that contain (-)
This pattern is matching all...
SCSI (Bus|Target) \d+\s*\.*^\(^\-^\)|Capacit y (\.+?[^(][^-][^)]|\.+?[(][ +][)]) [\d,]+? [kmg]Bytes \(\d+ Blocks\)
SCSI Bus 0
SCSI Target 0 ..................(+) COMPAQ BF03685A35
Capacity ......................(+) 34,732 MBytes (71132000 Blocks)
Serial Number .................(+) 3HX14GZ300007402A8CA
Firmware Version ..............(+) HPB4
AND
SCSI Bus 0
SCSI Target 0 .................. COMPAQ BF03685A35
Capacity ...................... 34,732 MBytes (71132000 Blocks)
Serial Number ................. 3HX14GZ300007402A8CA
Firmware Version .............. HPB4
BUT NOT
SCSI Bus 0
SCSI Target 0 ..................(-) COMPAQ BF03685A35
Capacity ......................(-) 34,732 MBytes (71132000 Blocks)
Serial Number .................(-) 3HX14GZ300007402A8CA
Firmware Version ..............(-) HPB4
Obviously SCSI Bus 0 would be matched in all three - and that's fine, but I want to exclude lines that contain (-)
This pattern is matching all...
SCSI (Bus|Target) \d+\s*\.*^\(^\-^\)|Capacit
ASKER
I'm using vbs/vb6.
The examples are nice - I've been going through a few tutorial sites, but I just don't 'get' it (yet, I hope)... :^)
The examples are nice - I've been going through a few tutorial sites, but I just don't 'get' it (yet, I hope)... :^)
Some things to possibly help you along your way, well that is until some expert answers your questions!
There is something called RegexBuddy which looks quite good - http://www.regexbuddy.com unfortunately there is no trial software, just full version so not worth it unless u got loads of money and can afford to waste money on things like this :)
There is a free one, but its .Net, http://www.sellsbrothers.com/tools/
Sorry, couldnt be more help
one last thing, out of your tutorials, have u seen the one from MS? most likely u have, but just in case http://support.microsoft.com/default.aspx?scid=kb;en-us;818802
There is something called RegexBuddy which looks quite good - http://www.regexbuddy.com unfortunately there is no trial software, just full version so not worth it unless u got loads of money and can afford to waste money on things like this :)
There is a free one, but its .Net, http://www.sellsbrothers.com/tools/
Sorry, couldnt be more help
one last thing, out of your tutorials, have u seen the one from MS? most likely u have, but just in case http://support.microsoft.com/default.aspx?scid=kb;en-us;818802
ASKER
I've got .Net as well - perhaps I'll try that one.
I've been just 'trying' different patterns in vb6 (debugger) to try and find a good match - but no luck yet...
Thanx.
I've been just 'trying' different patterns in vb6 (debugger) to try and find a good match - but no luck yet...
Thanx.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Not that it will make a difference, but before the xBytes, I have:
[\d,]+?
When I only explained it as
[\d,]+
Since the ? wasn't necessary here. Using +? is a special case not needed here, but I'd be happy to explain why you'd use +? or *? instead of just + or *.
If you used something like:
".*"
That would return anything and everything up to a line feed character. However, if you only wanted everything up to and including "sirbounty", you'd use:
".*?sirbounty"
The ? makes the wildcard only applicable up to whatever comes after it
[\d,]+?
When I only explained it as
[\d,]+
Since the ? wasn't necessary here. Using +? is a special case not needed here, but I'd be happy to explain why you'd use +? or *? instead of just + or *.
If you used something like:
".*"
That would return anything and everything up to a line feed character. However, if you only wanted everything up to and including "sirbounty", you'd use:
".*?sirbounty"
The ? makes the wildcard only applicable up to whatever comes after it
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx for the explanation everyone.
Out of close to 200 text files, this is now working (current method) on all but 3 (was all but 10).
So, I'll be going through these suggestions probably on Monday.
Extra thanx for the explanations. I've read through some of them and I 'think' I'm starting to get it. :^)
Out of close to 200 text files, this is now working (current method) on all but 3 (was all but 10).
So, I'll be going through these suggestions probably on Monday.
Extra thanx for the explanations. I've read through some of them and I 'think' I'm starting to get it. :^)
ASKER
Matt - your first comment seems to work on a few test servers.
"Live" run tomorrow night - so I'll let you know...
"Live" run tomorrow night - so I'll let you know...
ASKER
Sorry for the slight delay - had some other major bugs to work out.
We do want to pull back the serial number info as well, so I tried the regex (posted by Dragon_Krome):
SCSI (Bus|Target) \d+\s+SCSI Target \d+ \.+(\(\+\))? ([\w\s]+) Capacity \.+(\(\+\))? (([\d,]+) ([KMG]bytes)) \((\d+) Blocks\)\s+Serial Number \.+(\(\+\))? \w+\s+Firmware Version \.+(\(\+\))? \w+
But it doesn't appear to be working for me - it skips right over the test (value at that point is:
SCSI Bus 0
I'm not sure how to modify the other two to include serial number info...
We do want to pull back the serial number info as well, so I tried the regex (posted by Dragon_Krome):
SCSI (Bus|Target) \d+\s+SCSI Target \d+ \.+(\(\+\))? ([\w\s]+) Capacity \.+(\(\+\))? (([\d,]+) ([KMG]bytes)) \((\d+) Blocks\)\s+Serial Number \.+(\(\+\))? \w+\s+Firmware Version \.+(\(\+\))? \w+
But it doesn't appear to be working for me - it skips right over the test (value at that point is:
SCSI Bus 0
I'm not sure how to modify the other two to include serial number info...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is what I have from before, with the above added...
If RegEx.Test(FileCont(i)) Then
tempArr(0) = RegEx.Execute(FileCont(i)) .Item(0).S ubMatches( 0)
Else
RegEx.Pattern = "SCSI Target (\d+)"
If RegEx.Test(FileCont(i)) Then
tempArr(1) = RegEx.Execute(FileCont(i)) .Item(0).S ubMatches( 0)
Else
RegEx.Pattern = "Capacity \S+\s(.+?)\s"
If RegEx.Test(FileCont(i)) Then
tempArr(2) = RegEx.Execute(FileCont(i)) .Item(0).S ubMatches( 0)
ReDim Preserve DriveArray(iCnt)
DriveArray(iCnt) = tempArr
iCnt = iCnt + 1
Else
RegEx.Pattern = "Serial Number \.+\(?[^-]?\)? ([a-z0-9]+)"
If RegEx.Test(FileCont(i)) Then
tempArr(3) = RegEx.Execute(FileCont(i)) .Item(0).S ubMatches( 0)
ReDim Preserve DriveArray(iCnt)
DriveArray(iCnt) = tempArr
iCnt = iCnt + 1
End If
End If
End If
End If
Next
But should
tempArr(0) = RegEx.Execute(FileCont(i)) .Item(0).S ubMatches( 0)
Be
tempArr(0) = RegEx.Execute(FileCont(i)) .Item(0)
Cause the value of the first is "0", while the latter is "SCSI Bus 0" (I'm stepping through it using VB)
If RegEx.Test(FileCont(i)) Then
tempArr(0) = RegEx.Execute(FileCont(i))
Else
RegEx.Pattern = "SCSI Target (\d+)"
If RegEx.Test(FileCont(i)) Then
tempArr(1) = RegEx.Execute(FileCont(i))
Else
RegEx.Pattern = "Capacity \S+\s(.+?)\s"
If RegEx.Test(FileCont(i)) Then
tempArr(2) = RegEx.Execute(FileCont(i))
ReDim Preserve DriveArray(iCnt)
DriveArray(iCnt) = tempArr
iCnt = iCnt + 1
Else
RegEx.Pattern = "Serial Number \.+\(?[^-]?\)? ([a-z0-9]+)"
If RegEx.Test(FileCont(i)) Then
tempArr(3) = RegEx.Execute(FileCont(i))
ReDim Preserve DriveArray(iCnt)
DriveArray(iCnt) = tempArr
iCnt = iCnt + 1
End If
End If
End If
End If
Next
But should
tempArr(0) = RegEx.Execute(FileCont(i))
Be
tempArr(0) = RegEx.Execute(FileCont(i))
Cause the value of the first is "0", while the latter is "SCSI Bus 0" (I'm stepping through it using VB)
ASKER
Scratch that - I was missing the logic...
That depends, I guess. I thought you only wanted the "0" returned from it. If you want the full line, then yes remove the .submatches(0) portion (that goes for each part of it).
You'll want to remove the:
ReDim Preserve DriveArray(iCnt)
DriveArray(iCnt) = tempArr
iCnt = iCnt + 1
From the capacity match block, otherwise you'll get double the data returned, with half having serial numbers and the other half not having them. Also, don't forget to change the "ReDim tempArr(2)" line to 3, for the serial number.
You'll want to remove the:
ReDim Preserve DriveArray(iCnt)
DriveArray(iCnt) = tempArr
iCnt = iCnt + 1
From the capacity match block, otherwise you'll get double the data returned, with half having serial numbers and the other half not having them. Also, don't forget to change the "ReDim tempArr(2)" line to 3, for the serial number.
ASKER
Nope - it's working fine...except.
This is what I'm getting from the test file I'm using:
0|0|34,732|3HX1TTPK0000742 4CX52
0|1|34,732|A0A1P38035R2033 2
1|0|34,732|3HX0M4N40000734 2W6UF
1|1|34,732|3HX0LC3J0000734 2BHV7
1|2|34,732|3HX0NLH00000734 206NK|
1|3|34,732|3HX0G1AP0000734 2X1YC|
1|4|34,732|3HX0M2ZR0000734 2BJCK|
1|5|34,732|3HX0N1MK0000734 2FV42|
1|5|34,732|9J27FLW1XCZ3|
1|5|34,732|P432A0EBFM5HXR
Problem is - obviously there can't be 3 disks on target 5 (bus 1).
The latter 2 serial numbers come from the s/n of the subsystem and another installed component.
I'm not sure of a way to 'stop' searching after all are retrieved, cause "Serial Number" obviously occurs more than just in those blocks. This is the data including the last drive and the data blocks following it...perhaps you can spot something - I just hope it's static enough to cover all intances - not ever server will have an external storage cabinet, but I 'think' all internals are referred to as Compaq ProLiant Storage Box 0 - so maybe that would be the line to stop scanning at.
SCSI Target 5 ..................... COMPAQ BF03685A35
Capacity ......................... 34,732 MBytes (71132000 Blocks)
Serial Number .................... 3HX0N1MK00007342FV42
Firmware Version ................. HPB3
Compaq ProLiant Storage Box 0 ....... COMPAQ PROLIANT 4L6I
Firmware Version ................... 1.84
Storage Slot 0 ..................... COMPAQ BF03685A35 (wide)
Storage Slot 1 ..................... COMPAQ BF036863B5 (wide)
Storage Slot 2 ..................... [empty]
Storage Slot 3 ..................... [empty]
Storage Slot 4 ..................... [empty]
Storage Slot 5 ..................... [empty]
Operating Temperature .............. normal
Compaq ProLiant Storage Box 1 ....... COMPAQ PROLIANT 4LEE
Firmware Version ................... JB4F
Serial Number ...................... 9J27FLW1XCZ3
Storage Slot 0 ..................... COMPAQ BF03685A35 (wide)
Storage Slot 1 ..................... COMPAQ BF03685A35 (wide)
Storage Slot 2 ..................... COMPAQ BF03685A35 (wide)
Storage Slot 3 ..................... COMPAQ BF03685A35 (wide)
Storage Slot 4 ..................... COMPAQ BF03685A35 (wide)
Storage Slot 5 ..................... COMPAQ BF03685A35 (wide)
Cooling Fan(s) ..................... operational
Operating Temperature .............. normal
Redundant Power Supply ............. operational
I'll also be opening a new question to grab the firmware - I neglected to spot that data was in there. I don't want it answered here though, cause it appears the scope of this question is just about at its conclusion.
Thanx!
This is what I'm getting from the test file I'm using:
0|0|34,732|3HX1TTPK0000742
0|1|34,732|A0A1P38035R2033
1|0|34,732|3HX0M4N40000734
1|1|34,732|3HX0LC3J0000734
1|2|34,732|3HX0NLH00000734
1|3|34,732|3HX0G1AP0000734
1|4|34,732|3HX0M2ZR0000734
1|5|34,732|3HX0N1MK0000734
1|5|34,732|9J27FLW1XCZ3|
1|5|34,732|P432A0EBFM5HXR
Problem is - obviously there can't be 3 disks on target 5 (bus 1).
The latter 2 serial numbers come from the s/n of the subsystem and another installed component.
I'm not sure of a way to 'stop' searching after all are retrieved, cause "Serial Number" obviously occurs more than just in those blocks. This is the data including the last drive and the data blocks following it...perhaps you can spot something - I just hope it's static enough to cover all intances - not ever server will have an external storage cabinet, but I 'think' all internals are referred to as Compaq ProLiant Storage Box 0 - so maybe that would be the line to stop scanning at.
SCSI Target 5 ..................... COMPAQ BF03685A35
Capacity ......................... 34,732 MBytes (71132000 Blocks)
Serial Number .................... 3HX0N1MK00007342FV42
Firmware Version ................. HPB3
Compaq ProLiant Storage Box 0 ....... COMPAQ PROLIANT 4L6I
Firmware Version ................... 1.84
Storage Slot 0 ..................... COMPAQ BF03685A35 (wide)
Storage Slot 1 ..................... COMPAQ BF036863B5 (wide)
Storage Slot 2 ..................... [empty]
Storage Slot 3 ..................... [empty]
Storage Slot 4 ..................... [empty]
Storage Slot 5 ..................... [empty]
Operating Temperature .............. normal
Compaq ProLiant Storage Box 1 ....... COMPAQ PROLIANT 4LEE
Firmware Version ................... JB4F
Serial Number ...................... 9J27FLW1XCZ3
Storage Slot 0 ..................... COMPAQ BF03685A35 (wide)
Storage Slot 1 ..................... COMPAQ BF03685A35 (wide)
Storage Slot 2 ..................... COMPAQ BF03685A35 (wide)
Storage Slot 3 ..................... COMPAQ BF03685A35 (wide)
Storage Slot 4 ..................... COMPAQ BF03685A35 (wide)
Storage Slot 5 ..................... COMPAQ BF03685A35 (wide)
Cooling Fan(s) ..................... operational
Operating Temperature .............. normal
Redundant Power Supply ............. operational
I'll also be opening a new question to grab the firmware - I neglected to spot that data was in there. I don't want it answered here though, cause it appears the scope of this question is just about at its conclusion.
Thanx!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Looks to be it. It's working on this file. Let me try it on a few more and I'll post the results.
Thanx!
Thanx!
ASKER
So far so good - works on my test server...190~something servers left to test... :)
I think I'll roll this new function out and see where we stand...hopefully they will all work as smoothly.
If not, I'll post the troublemakers here, if there aren't too many.
Many thanx again.
I think I'll roll this new function out and see where we stand...hopefully they will all work as smoothly.
If not, I'll post the troublemakers here, if there aren't too many.
Many thanx again.
ASKER
Of all the ones reporting (I 'think' that's all of them) - we have 100%!
Thanx again Matt - and thanx to everyone else that helped explain this to me.
I 'may' come back for the firmware later - if I do, I'll post an invite here.
Thanx again Matt - and thanx to everyone else that helped explain this to me.
I 'may' come back for the firmware later - if I do, I'll post an invite here.
some examples from o'reilly here that may help you http://examples.oreilly.com/regex/
sorry couldnt be more help