Re: Finding duplicates with RegEX
- From: Alexander Mueller <millerax@xxxxxxxxxxx>
- Date: Fri, 14 Sep 2007 00:26:40 +0200
scott schrieb:
For the sample below, I'm trying to construct an expression to capture drive sizes (second word) and the corrisponding serial id (fourth word). The expression I have so far is this : '\w*(\d{2,3}.\dGB).*(\(.*\))'
It only returns part of the drive size (ie: 74.4GB instead of 274.4GB).
That's because you need to denote the literal 'dot' as: \.
instead of an arbitrary character: .
> Can the expression also filter duplicates?
Not directly, but you can handle it yourself, by letting a
function process (sub)matches while calling
RegExp-Replace:
MfG,
Alex
Dim src
Dim dic
Dim r
src = _
"XMTOMC320 274.4GB 512B/sect (A8188BKE)" & vbCrLf _
& "XMTOMC320 136.5GB 512B/sect (A818DNME)" & vbCrLf _
& "XSCHT6146F 68.0GB 520B/sect (3HYX5ERR0000750175VW)" & vbCrLf _
& vbCrLf _
& "XMTOMC320 274.4GB 512B/sect (A8188BKE)" & vbCrLf _
& "XMTOMC320 136.5GB 512B/sect (A818DNME)" & vbCrLf _
& "XSCHT6146F 68.0GB 520B/sect (3HYX5ERR0000750175VW)" & vbCrLf
Set dic = CreateObject("Scripting.Dictionary")
Set r = New RegExp
r.MultiLine = True
r.Global = True
r.Pattern = "^\w+ +(\d{2,3}\.\dGB) +.*\((.+)\)$"
Call r.Replace (src, GetRef("GetDriveSize"))
WSH.Echo Join(dic.Items, vbCrLf)
Sub GetDriveSize (match, s1, s2, pos, src)
Dim key
key = s1 & " " & s2
If Not dic.Exists(key) Then
dic.Add key, "Serial: " & s2 & ", Size: " & s1
End If
End Sub
.
XMTOMC320 274.4GB 512B/sect (A8188BKE)
XMTOMC320 136.5GB 512B/sect (A818DNME)
XSCHT6146F 68.0GB 520B/sect (3HYX5ERR0000750175VW)
XMTOMC320 488.7GB 512B/sect (A818NGCE)
XMTOMC320 274.4GB 512B/sect (A8188BKE)
XMTOMC320 136.5GB 512B/sect (A818DNME)
XMTOMC320 488.7GB 512B/sect (A818NGCE)
XSCHT6146F 68.0GB 520B/sect (3HYX5ERR0000750175VW)
- References:
- Finding duplicates with RegEX
- From: scott
- Finding duplicates with RegEX
- Prev by Date: Re: Determine what permissions a group has?
- Next by Date: How can I script the adding of additional mailboxes to a users account in Outlook at login?
- Previous by thread: Finding duplicates with RegEX
- Next by thread: Re: Finding duplicates with RegEX
- Index(es):
Relevant Pages
|
Loading