Hi,

Is there a way to search for multiple strings in a text document. I am
looking for 5 alphabets (which can be upper or lower) or numbers etc
and am using instr to do that. IT makes for a very long code. Is there
a smarter way to use instr( textstring, search string) where it will
let me search for more than 1 thing a time incl upper and lower

For each desc in descol
if level = 0 then
objFileW.Write "Name:" & desc
elseif level=1 and (instr(desc,"k", 1) or instr(desc,"M",1 or
inst(desc, "K",1) ......... then

SA

Re: framing a smarter search string in vbScript by Pegasus

Pegasus
Mon May 05 13:57:53 CDT 2008


<karsagarwal@gmail.com> wrote in message
news:b286acab-e103-49df-adb5-1c7e13681057@w34g2000prm.googlegroups.com...
> Hi,
>
> Is there a way to search for multiple strings in a text document. I am
> looking for 5 alphabets (which can be upper or lower) or numbers etc
> and am using instr to do that. IT makes for a very long code. Is there
> a smarter way to use instr( textstring, search string) where it will
> let me search for more than 1 thing a time incl upper and lower
>
> For each desc in descol
> if level = 0 then
> objFileW.Write "Name:" & desc
> elseif level=1 and (instr(desc,"k", 1) or instr(desc,"M",1 or
> inst(desc, "K",1) ......... then
>
> SA

You can get this functionality with a single command line from
the Command Prompt. The command

FINDSTR /i "hello there" c:\test.txt

will search for the words "hello" or "there" in c:\test.txt. The
search is not case sensitive.



Re: framing a smarter search string in vbScript by Tom

Tom
Mon May 05 14:06:02 CDT 2008

On May 5, 2:50 pm, "karsagar...@gmail.com" <karsagar...@gmail.com>
wrote:
> Hi,
>
> Is there a way to search for multiple strings in a text document. I am
> looking for 5 alphabets (which can be upper or lower) or numbers etc
> and am using instr to do that. IT makes for a very long code. Is there
> a smarter way to use instr( textstring, search string) where it will
> let me search for more than 1 thing a time incl upper and lower
>
> For each desc in descol
> if level = 0 then
> objFileW.Write "Name:" & desc
> elseif level=1 and (instr(desc,"k", 1) or instr(desc,"M",1 or
> inst(desc, "K",1) ......... then
>
> SA

Probably using the RegExp provided by scripting would be teh best
solution. For example, the following is derived from the example
provided by the WSH documentation ...

For each desc in descol
if level = 0 then
objFileW.Write "Name:" & desc
elseif level=1 and (RegExpTest("K|M", desc)) Then ...

Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches, bRet ' Create variables
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(strng) ' Execute search.
bRet = False
For Each Match in Matches ' Iterate Matches collection.
bRet = True
Next
RegExpTest = bRet
End Function

WSH 5.6 documentation download (URL all one line)
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Re: framing a smarter search string in vbScript by karsagarwal

karsagarwal
Mon May 05 14:09:23 CDT 2008

On May 5, 12:06=A0pm, Tom Lavedas <tglba...@cox.net> wrote:
> On May 5, 2:50 pm, "karsagar...@gmail.com" <karsagar...@gmail.com>
> wrote:
>
> > Hi,
>
> > Is there a way to search for multiple strings in a text document. I am
> > looking for 5 alphabets (which can be upper or lower) or numbers =A0etc
> > and am using instr to do that. IT makes for a very long code. Is there
> > a smarter way to use instr( textstring, search string) where it will
> > let me search for more than 1 thing a time incl upper and lower
>
> > For each desc in descol
> > =A0 =A0 =A0if level =3D 0 then
> > =A0 =A0 =A0 =A0 =A0 objFileW.Write "Name:" & desc
> > =A0 =A0 =A0elseif level=3D1 and (instr(desc,"k", 1) or instr(desc,"M",1 =
or
> > inst(desc, "K",1) ......... then
>
> > SA
>
> Probably using the RegExp provided by scripting would be teh best
> solution. =A0For example, the following is derived from the example
> provided by the WSH documentation ...
>
> For each desc in descol
> =A0 =A0 =A0if level =3D 0 then
> =A0 =A0 =A0 =A0 =A0 objFileW.Write "Name:" & desc
> =A0 =A0 =A0elseif level=3D1 and (RegExpTest("K|M", desc)) Then ...
>
> Function RegExpTest(patrn, strng)
> =A0 =A0Dim regEx, Match, Matches, bRet =A0 ' Create variables
> =A0 =A0Set regEx =3D New RegExp =A0 =A0 =A0' Create a regular expression.
> =A0 =A0regEx.Pattern =3D patrn =A0 =A0 =A0 ' Set pattern.
> =A0 =A0regEx.IgnoreCase =3D True =A0 =A0 ' Set case insensitivity.
> =A0 =A0regEx.Global =3D True =A0 =A0 =A0 =A0 ' Set global applicability.
> =A0 =A0Set Matches =3D regEx.Execute(strng) =A0 ' Execute search.
> =A0 =A0bRet =3D False
> =A0 =A0For Each Match in Matches =A0 ' Iterate Matches collection.
> =A0 =A0 =A0 bRet =3D True
> =A0 =A0Next
> =A0 =A0RegExpTest =3D bRet
> End Function
>
> WSH 5.6 documentation download (URL all one line)http://www.microsoft.com/=
downloads/details.aspx?FamilyId=3D01592C48-207...
>
> Tom Lavedas
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3Dhttp://members.cox.net/tglbatch/wsh/

THank you this should be very helpful.

SA

Re: framing a smarter search string in vbScript by James

James
Mon May 05 14:13:36 CDT 2008

<karsagarwal@gmail.com> wrote in message
news:b286acab-e103-49df-adb5-1c7e13681057@w34g2000prm.googlegroups.com...
> Hi,
>
> Is there a way to search for multiple strings in a text document. I am
> looking for 5 alphabets (which can be upper or lower) or numbers etc
> and am using instr to do that. IT makes for a very long code. Is there
> a smarter way to use instr( textstring, search string) where it will
> let me search for more than 1 thing a time incl upper and lower
>
> For each desc in descol
> if level = 0 then
> objFileW.Write "Name:" & desc
> elseif level=1 and (instr(desc,"k", 1) or instr(desc,"M",1 or
> inst(desc, "K",1) ......... then

Have you considered using regular expressions?

http://msdn.microsoft.com/en-us/library/ms974570.aspx

If you are not already experienced with them, there is a learning curve,
but it is very much worth it.

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Set oRegEx = CreateObject("VBScript.RegExp")

'The below pattern will search for upper or lower case 'k' or upper case 'M'
oRegEx.Pattern = "[kKM]"

If oRegEx.Test(desc) Then
'your code
End If
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You could, for instance use a pattern like "[aAbBcDEf1256]" to search
for upper or lower case a or b, lower case c, upper case D or E or number 1,
2, 5 or 6. If you don't want to distunguish between upper and lower case,
you can use 'oRegEx.IgnoreCase = True'



Re: framing a smarter search string in vbScript by karsagarwal

karsagarwal
Mon May 05 14:29:28 CDT 2008

On May 5, 12:13=A0pm, "James Whitlow" <jwhitlow.60372...@bloglines.com>
wrote:
> <karsagar...@gmail.com> wrote in message
>
> news:b286acab-e103-49df-adb5-1c7e13681057@w34g2000prm.googlegroups.com...
>
> > Hi,
>
> > Is there a way to search for multiple strings in a text document. I am
> > looking for 5 alphabets (which can be upper or lower) or numbers =A0etc
> > and am using instr to do that. IT makes for a very long code. Is there
> > a smarter way to use instr( textstring, search string) where it will
> > let me search for more than 1 thing a time incl upper and lower
>
> > For each desc in descol
> > =A0 =A0 if level =3D 0 then
> > =A0 =A0 =A0 =A0 =A0objFileW.Write "Name:" & desc
> > =A0 =A0 elseif level=3D1 and (instr(desc,"k", 1) or instr(desc,"M",1 or
> > inst(desc, "K",1) ......... then
>
> =A0 =A0 Have you considered using regular expressions?
>
> http://msdn.microsoft.com/en-us/library/ms974570.aspx
>
> =A0 =A0 If you are not already experienced with them, there is a learning =
curve,
> but it is very much worth it.
>
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Set oRegEx =3D CreateObject("VBScript.RegExp")
>
> 'The below pattern will search for upper or lower case 'k' or upper case '=
M'
> oRegEx.Pattern =3D "[kKM]"
>
> If oRegEx.Test(desc) Then
> =A0'your code
> End If
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> =A0 =A0 You could, for instance use a pattern like "[aAbBcDEf1256]" to sea=
rch
> for upper or lower case a or b, lower case c, upper case D or E or number =
1,
> 2, 5 or 6. If you don't want to distunguish between upper and lower case,
> you can use 'oRegEx.IgnoreCase =3D True'

This is great. I have a lot of searching to do so this will be very
helpful. Thanks for the examples and links.

SA

Re: framing a smarter search string in vbScript by Paul

Paul
Tue May 06 00:13:25 CDT 2008


<karsagarwal@gmail.com> wrote in message
news:bf49dedb-2aae-4147-a4cb-0edfcc2f05f9@c19g2000prf.googlegroups.com...
On May 5, 12:13 pm, "James Whitlow" <jwhitlow.60372...@bloglines.com>
wrote:
> <karsagar...@gmail.com> wrote in message
>
> news:b286acab-e103-49df-adb5-1c7e13681057@w34g2000prm.googlegroups.com...
>
> > Hi,
>
> > Is there a way to search for multiple strings in a text document.
> > I am
> > looking for 5 alphabets (which can be upper or lower) or numbers
> > etc
> > and am using instr to do that. IT makes for a very long code. Is
> > there
> > a smarter way to use instr( textstring, search string) where it
> > will
> > let me search for more than 1 thing a time incl upper and lower
>
> > For each desc in descol
> > if level = 0 then
> > objFileW.Write "Name:" & desc
> > elseif level=1 and (instr(desc,"k", 1) or instr(desc,"M",1 or
> > inst(desc, "K",1) ......... then
>
> Have you considered using regular expressions?
>
> http://msdn.microsoft.com/en-us/library/ms974570.aspx
>
> If you are not already experienced with them, there is a learning
> curve,
> but it is very much worth it.
>
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Set oRegEx = CreateObject("VBScript.RegExp")
>
> 'The below pattern will search for upper or lower case 'k' or upper
> case 'M'
> oRegEx.Pattern = "[kKM]"
>
> If oRegEx.Test(desc) Then
> 'your code
> End If
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> You could, for instance use a pattern like "[aAbBcDEf1256]" to
> search
> for upper or lower case a or b, lower case c, upper case D or E or
> number 1,
> 2, 5 or 6. If you don't want to distunguish between upper and lower
> case,
> you can use 'oRegEx.IgnoreCase = True'

This is great. I have a lot of searching to do so this will be very
helpful. Thanks for the examples and links.

----------------

The learning curve for regular expressions can be substantial.
Translating what you want into 'RegularExpression-ese' is a difficult.
You can find many example regular expressions on line, but figuring
out what they do is also difficult. I don't know if there is a
standard for regular expressions, but if there is, VBScript definitely
doesn't adhere to it.

One handy tool for learning, writing, analyzing, and testing regular
expressions is "Regular Expression Workbench". This free tool uses an
early release of dot net, and its regular expression engine, so just
because you get something working with the tool doesn't necessarily
mean it will work correctly with VBScript's RE engine. You can
download it here:
http://code.msdn.microsoft.com/RegexWorkbench/Release/ProjectReleases.aspx?ReleaseId=406.
I especially like the 'analyze' feature which breaks a regular
expression into a series of logical pieces and gives a short
description of what each piece does. The analyze feature will help
you recognize features of a regular expression that are not available
in VBScript (you just have to learn the key words and phrases that
indicate one of these features).

http://regexlib.com/Default.aspx contains a searchable inventory of
over 2000 regular expressions, many of which work properly with
VBScript with few or no modifications.

-Paul Randall



Re: framing a smarter search string in vbScript by James

James
Tue May 06 07:26:30 CDT 2008

"Paul Randall" <paulr901@cableone.net> wrote in message
news:eVPUbfzrIHA.5872@TK2MSFTNGP04.phx.gbl...
>
> The learning curve for regular expressions can be substantial. Translating
> what you want into 'RegularExpression-ese' is a difficult. You can find
> many example regular expressions on line, but figuring out what they do is
> also difficult. I don't know if there is a standard for regular
> expressions, but if there is, VBScript definitely doesn't adhere to it.
>
> One handy tool for learning, writing, analyzing, and testing regular
> expressions is "Regular Expression Workbench". This free tool uses an
> early release of dot net, and its regular expression engine, so just
> because you get something working with the tool doesn't necessarily mean
> it will work correctly with VBScript's RE engine. You can download it
> here:
> http://code.msdn.microsoft.com/RegexWorkbench/Release/ProjectReleases.aspx?ReleaseId=406. I
> especially like the 'analyze' feature which breaks a regular expression
> into a series of logical pieces and gives a short description of what each
> piece does. The analyze feature will help you recognize features of a
> regular expression that are not available in VBScript (you just have to
> learn the key words and phrases that indicate one of these features).
>
> http://regexlib.com/Default.aspx contains a searchable inventory of over
> 2000 regular expressions, many of which work properly with VBScript with
> few or no modifications.

Thanks for the info, Paul. I have downloaded the referenced program.
Sounds interesting!

I agree with you that the learning curve is high, but I think it is well
worth pursuing for anyone who does anything beyond very basic pattern
matching.

I have also found some deficiencies in the VBScript implimentation of
regular expressions, but I am satisfied. I would be almost totally satisfied
if not for the ommision of 'lookbehind'. I am still a little puzzled by why
Microsoft included 'lookahead' and excluded 'lookbehind'. In a few
situations I could not get a pattern working for the lack of 'lookbehind'.

I use the below list of sites for syntax reference.

http://msdn.microsoft.com/en-us/library/ms974570.aspx
http://msdn.microsoft.com/en-us/library/ae5bf541(VS.71).aspx
http://regexlib.com/CheatSheet.aspx



Re: framing a smarter search string in vbScript by Paul

Paul
Tue May 06 10:23:45 CDT 2008


"James Whitlow" <jwhitlow.60372693@bloglines.com> wrote in message
news:OM0xrR3rIHA.3456@TK2MSFTNGP05.phx.gbl...
> "Paul Randall" <paulr901@cableone.net> wrote in message
> news:eVPUbfzrIHA.5872@TK2MSFTNGP04.phx.gbl...
>>
>> The learning curve for regular expressions can be substantial.
>> Translating what you want into 'RegularExpression-ese' is a
>> difficult. You can find many example regular expressions on line,
>> but figuring out what they do is also difficult. I don't know if
>> there is a standard for regular expressions, but if there is,
>> VBScript definitely doesn't adhere to it.
>>
>> One handy tool for learning, writing, analyzing, and testing
>> regular expressions is "Regular Expression Workbench". This free
>> tool uses an early release of dot net, and its regular expression
>> engine, so just because you get something working with the tool
>> doesn't necessarily mean it will work correctly with VBScript's RE
>> engine. You can download it here:
>> http://code.msdn.microsoft.com/RegexWorkbench/Release/ProjectReleases.aspx?ReleaseId=406. I
>> especially like the 'analyze' feature which breaks a regular
>> expression into a series of logical pieces and gives a short
>> description of what each piece does. The analyze feature will help
>> you recognize features of a regular expression that are not
>> available in VBScript (you just have to learn the key words and
>> phrases that indicate one of these features).
>>
>> http://regexlib.com/Default.aspx contains a searchable inventory of
>> over 2000 regular expressions, many of which work properly with
>> VBScript with few or no modifications.
>
> Thanks for the info, Paul. I have downloaded the referenced
> program. Sounds interesting!
>
> I agree with you that the learning curve is high, but I think it
> is well worth pursuing for anyone who does anything beyond very
> basic pattern matching.
>
> I have also found some deficiencies in the VBScript
> implimentation of regular expressions, but I am satisfied. I would
> be almost totally satisfied if not for the ommision of 'lookbehind'.
> I am still a little puzzled by why Microsoft included 'lookahead'
> and excluded 'lookbehind'. In a few situations I could not get a
> pattern working for the lack of 'lookbehind'.
>
> I use the below list of sites for syntax reference.
>
> http://msdn.microsoft.com/en-us/library/ms974570.aspx
> http://msdn.microsoft.com/en-us/library/ae5bf541(VS.71).aspx
> http://regexlib.com/CheatSheet.aspx

Yes, learning the basics of regular expressions is well worth the
effort in many cases. One book I find handy is 'Regular Expression
Recipes for Windows Developers'. It has complete working regular
expression snippets to solve many problems, with variations in C#, dot
net, JavaScript, and VBScript, so you can see the variations in the
pattern these implimentations of regular expressions require. It also
shows how some limitations of VBScript's implimentation can be gotten
around. In general, if Regular Expression WorkBench's interpret
function indicates a negative lookbehind was used, then VBScript will
not be able to use that pattern.