Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My Nemesis Returns: RegEx help needed please 1

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
US
The one area I am worst at is going to be the best solution for my need.

I am piping the output of an NSLOOKUP command to a variable and splitting that to create an array.

I want to filter out the lines that start with "Server:" as well as "Address:" and I also want to strip out the lines starting with:
"Microsoft (R)"
"Copyright (C)"

Here is what I have so far

Code:
nslookupinfo = Split(strNsLookupStdOut,vbCr)
'Declare our variable
	Dim objRegExpr

	'Create an instance of the regexp object
	Set objRegExpr = New RegExp
	objRegExpr.Pattern = "Address:"
	objRegExpr.Global = True
	objRegExpr.IgnoreCase = True

For Each line In nslookupinfo
	Set colMatches = objRegExpr.Execute(line)
	If colMatches.Count = 0 Then
	  If Len(line) > 1 Then
		WScript.echo line
	  End If
	End If
Next

What I would like to know is if there is a way to specify multiple strings to check against without nesting RegEx executions? Any help is greatly appreciated.
 
You can test against multiple entries in one IF statement, like this:
Code:
msg="Give me text!"
str = inputbox(msg)

if lcase(str)="duck" or lcase(str)="goose" or lcase(str)="swan" then
    wscript.echo "A " & lcase(str) & " is a floating, swimming, flying animal."
else
    wscript.echo "A " & lcase(str) & " is not likely to survive in or on water or in the air."
end if

So using the InStr (In String) function:
Code:
msg="Give me text!"
str = inputbox(msg)

if InStr(lcase(str),"duck") or InStr(lcase(str),"goose") or InStr(lcase(str),"swan") then
    wscript.echo "Looks like you've entered the name of a floating, swimming, flying animal."
else
    wscript.echo "That animal is not likely to survive in or on water or in the air."
end if
To me, it looks like a slightly clumsy solution for which there's probably a more elegant approach, but it seems to work...

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, and so on)[/small]
 
Hi JJ, thanks for posting. I do know how to do what you demonstrated. The problem is as the number of patterns increases the command gets unruly. I believe RegEx to be more efficient and scalable in this case.

PHV, thank you for your post as well. I had seen the links you provided in another thread that you posted in as well. The second link seems to be bad. Unfortunately I am not seeing any examples in the first link that let you specify multiple patterns to search on.

I'd like to be able to do something similar to a Select Case where you can specify multiple criteria separated by commas. Do you know if that is possible?
 
Mark, I'd not spotted it was you!

My whole belief system is now shattered...

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, and so on)[/small]
 
The 2 links work well from me.
The second one is for alternation.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Interesting PHV, I get directed to MSDN and the following is displayed from that link:

Content not found
We apologize for the inconvenience, but the location you are seeking cannot be found. If you are looking for a particular document, please try one of the following areas:

But knowing to search on "alternation" was all I needed. I now have this working, thank you!

JJ, sorry if I burst your bubble, none of us know EVERYTHING. ;-)

For those following in my foot steps, the solution was to use:
objRegExpr.Pattern = "Address:|Server:"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top