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