From: Webbiz on
I'm trying to find the best way to go about extracting all strings that are
contained within parenthesis from a text box.

For example, if I were to paste the following inside a text box that accepts
multiple lines:

kULijEBWJIBLZx *PIC*
Epgcxrdx (203.177.74.138) -- Tuesday, 1 July 2008, at 11:03 am
wlgbzrEGueNsxXPw *PIC*
Sqkkcrli (203.158.221.227) -- Tuesday, 1 July 2008, at 11:02 am
WsRfHTwdzjQITpcYNf *PIC*
Kgffsexn (203.177.74.136) -- Tuesday, 1 July 2008, at 10:56 am
AaaWdFLjresIFvG *PIC*
Wrfrrfwo (219.133.45.202) -- Tuesday, 1 July 2008, at 10:55 am
qQfveyIUjAGlWxi *PIC*
Tgmwfsbe (59.166.116.189) -- Tuesday, 1 July 2008, at 10:51 am
PMTsXheSJVdTtlu *PIC*
Hnysdkau (211.38.131.22) -- Tuesday, 1 July 2008, at 10:49 am
kFhjuMFMRCVjkdooTJ *PIC*
Iwoskmkd (203.177.74.138) -- Tuesday, 1 July 2008, at 10:43 am
FkkTtnXLjwBWNB *PIC*
Bavsfuva (203.177.74.137) -- Tuesday, 1 July 2008, at 10:42 am
IoOYIviJDljjmdkaJi *PIC*
Tvyirrmg (203.177.74.138) -- Tuesday, 1 July 2008, at 10:38 am
raHvDLJgjOgvQ *PIC*

I'd like to strip out all the noise and just end up with the IP numbers
contained within all this text, such as...

203.177.74.138
203.158.221.227
203.177.74.136

Actually, I'd like to strip out the digits that follow the last decimal as
well.

203.177.74.
203.158.221.
203.177.74.

....as my final result and replace the text box data string with this
resulting information.

My web board is getting bombarded with these annoying spam posts with
fictious names and content. It's really tedious to manually go through
hundreds of these a day and get the IP numbers to ban them. So I thought try
parsing them out with a small VB app. Problem is, I've never done this
before.

While I use parse code I have that uses a delimiter, and assign the
delimiter to "(" where each IP starts, I can't assign an ending delimiter
")" to tell it where to stop reading into the array sWords.

I'm hoping someone here knows a quick way to do this.

Thanks.

Webbiz


From: Karl E. Peterson on
Webbiz wrote:
> While I use parse code I have that uses a delimiter, and assign the
> delimiter to "(" where each IP starts, I can't assign an ending delimiter
> ")" to tell it where to stop reading into the array sWords.
>
> I'm hoping someone here knows a quick way to do this.

The general idea is something like this:

' Air Code Alert!!!
Do
nStart = Instr(nStart + 1, Data, "(")
If nStart Then
nStop = Instr(nStart + 1, Data, ")")
If nStop Then
GoodStuff = Mid$(Data, nStart + 1, nStop - nStart)
Else
Exit Do
End If
End If
Loop While nStart

Some testing/tweaking may be required.
--
..NET: It's About Trust!
http://vfred.mvps.org


From: Jeff Johnson on
"Webbiz" <noreply(a)cox.net> wrote in message
news:uJDpJi62IHA.1192(a)TK2MSFTNGP05.phx.gbl...

> I'd like to strip out all the noise and just end up with the IP numbers
> contained within all this text, such as...
>
> 203.177.74.138
> 203.158.221.227
> 203.177.74.136
>
> Actually, I'd like to strip out the digits that follow the last decimal as
> well.
>
> 203.177.74.
> 203.158.221.
> 203.177.74.
>
> ...as my final result and replace the text box data string with this
> resulting information.

Add a reference to Microsoft VBScript Regular Expressions 5.5 and then put
this code somewhere and pass it your text blob:

Private Sub ExtractIPs(ByVal LogText As String)
Dim rgx As VBScript_RegExp_55.RegExp
Dim matches As VBScript_RegExp_55.MatchCollection
Dim match As VBScript_RegExp_55.match
Dim subMatches As VBScript_RegExp_55.subMatches

Set rgx = New VBScript_RegExp_55.RegExp

rgx.Pattern = "\((\d{1,3}.\d{1,3}.\d{1,3}.)\d{1,3}\)"
rgx.Global = True ' Important or you'll only get the first match
Set matches = rgx.Execute(LogText)

For Each match In matches
Debug.Print match.subMatches(0)
Next
End Sub

For production, you can change the Debug.Print part to a string
concatenation and then dump the results into your text box.


From: Bob O`Bob on
Webbiz wrote:
> I'm trying to find the best way to go about extracting all strings that are
> contained within parenthesis from a text box.



there must be an infinite number of ways to approach this.

Here's a state-machine version:


Public Function extractIPs(sIn As String) As String
Dim i As Long, ch As String
Dim bModeData As Boolean
'note: NO effort made to cope with nested parens

For i = 1 To Len(sIn)
ch = Mid$(sIn, i, 1)
Select Case ch
Case "("
bModeData = True
Case ")"
If bModeData Then
extractIPs = extractIPs & vbCrLf
bModeData = False
End If
Case Else
If bModeData Then
extractIPs = extractIPs & ch
End If
End Select
Next
End Function


enjoy!

Bob
--
From: Rick Rothstein (MVP - VB) on
> I'm trying to find the best way to go about extracting all strings that
> are contained within parenthesis from a text box.
>
> For example, if I were to paste the following inside a text box that
> accepts multiple lines:
>
> kULijEBWJIBLZx *PIC*
> Epgcxrdx (203.177.74.138) -- Tuesday, 1 July 2008, at 11:03 am
> wlgbzrEGueNsxXPw *PIC*
> Sqkkcrli (203.158.221.227) -- Tuesday, 1 July 2008, at 11:02 am
> WsRfHTwdzjQITpcYNf *PIC*
> Kgffsexn (203.177.74.136) -- Tuesday, 1 July 2008, at 10:56 am
> AaaWdFLjresIFvG *PIC*
> Wrfrrfwo (219.133.45.202) -- Tuesday, 1 July 2008, at 10:55 am
> qQfveyIUjAGlWxi *PIC*
> Tgmwfsbe (59.166.116.189) -- Tuesday, 1 July 2008, at 10:51 am
> PMTsXheSJVdTtlu *PIC*
> Hnysdkau (211.38.131.22) -- Tuesday, 1 July 2008, at 10:49 am
> kFhjuMFMRCVjkdooTJ *PIC*
> Iwoskmkd (203.177.74.138) -- Tuesday, 1 July 2008, at 10:43 am
> FkkTtnXLjwBWNB *PIC*
> Bavsfuva (203.177.74.137) -- Tuesday, 1 July 2008, at 10:42 am
> IoOYIviJDljjmdkaJi *PIC*
> Tvyirrmg (203.177.74.138) -- Tuesday, 1 July 2008, at 10:38 am
> raHvDLJgjOgvQ *PIC*
>
> I'd like to strip out all the noise and just end up with the IP numbers
> contained within all this text, such as...
>
> 203.177.74.138
> 203.158.221.227
> 203.177.74.136
>
> Actually, I'd like to strip out the digits that follow the last decimal as
> well.
>
> 203.177.74.
> 203.158.221.
> 203.177.74.
>
> ...as my final result and replace the text box data string with this
> resulting information.
>
> My web board is getting bombarded with these annoying spam posts with
> fictious names and content. It's really tedious to manually go through
> hundreds of these a day and get the IP numbers to ban them. So I thought
> try parsing them out with a small VB app. Problem is, I've never done this
> before.
>
> While I use parse code I have that uses a delimiter, and assign the
> delimiter to "(" where each IP starts, I can't assign an ending delimiter
> ")" to tell it where to stop reading into the array sWords.

Assuming your TextBox is named Text1 and you are using a CommandButton named
to initiate the process, this should do what you asked...

Private Sub Command1_Click()
Dim X As Long
Dim Temp As String, NewText As String
Dim ParenParts() As String, IPnumbers() As String
IPnumbers = Split(Text1.Text, "(")
For X = 1 To UBound(IPnumbers)
Temp = Split(IPnumbers(X), ")")(0)
NewText = NewText & Left(Temp, InStrRev(Temp, ".")) & vbCrLf
Next
Text1.Text = NewText
End Sub

Rick