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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBscript RegExp 1

Status
Not open for further replies.

appnair

Programmer
May 29, 2003
1,770
US
I am not sure if this is the right place or whether there is a forum for reg expressions
Situation:I have a folder windows that has files starting
with timings1_0.csv thru timings1_9.csv and the pattern repeats like timings5_4.csv ,timings3_1.csv ,I guess you get the idea.I am constrained by my programming environment,I cannot use anything other than vbscript which is version5.6,So I started with aregexp pattern which is as under.What I want is a pattern that can pick up a "zero" 0 in a file name and the file has to start with "timing".The below pattern does pick up "0"'s but being devils advocate
I put a file called "pimings1_0.csv" and my regexp picked that also as a candidate.So obviously I am doing my pat match wrongly,but cannot figure it out.
Set re = new regexp
re.pattern ="T*0\.csv"
re.IgnoreCase = true
re.Global = true
expressionmatch=re.Test(oFile.Name)
in the above example oFile.Name will be replaced by code as
pimings1_0.csv and so on and I have a wscript.echo statement telling me it has found a match or not.

If one of the vbscript gurus can help me why the expression is going wrong or share your experiences about its reliabilty.


Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
re.pattern = "^timings[0-9]_0\.csv"

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Wonderful .Where was I wrong(pimings1_0.csv).So long as it works fine.You deserve a star as well

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
Where was I wrong(pimings1_0.csv)"


Well, if we state your pattern ("T*0\.csv") in words, it would be:

"Look for the letter T(T) zero or more times(*) followed by the number 0(0) then a .(\.) then csv(csv)"

pimings1_0.csv does fit the pattern that you specified.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
wonderful .That is what I hoped to hear.I basically lost touch of sanity while I was doing this.Thanks for the explanation too.I really appreciate your input

Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top