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

Regular Expression Question

Status
Not open for further replies.

nazzaro

Programmer
Jun 28, 2000
31
US
Is there a relatively simple way to find out the position in a string where a VbScript "Regular Expression" first fails?

I'm using a regular expression to test an entire string, with parentheses set to "capture" submatch info for several substrings.

The problem is that the "submatch" info is only saved (In the SubMatches collection in an item of the Matches collection) if the whole string matches (since the SubMatches collection is a collection of each Match Item and there are no Match Items if the whole string doesn't match the overall pattern).

Any suggestions would be appreciated.

Thanks.

For any interested, here is some of the code (NOTE - strTest would normally be read from a file, not supplied explicitly as in this example):


set reLine1 = new regexp

strTest="02/29/00 01 01 0060 08 1200 1100 !! 02/29/00 01 01 0060 08 1200 0000" + vbCrLf

'Checks for first column
strLt1="(" + strOpDate + ")" 'Check date
strLt1=strLt1 + "( (?:0[1-9])|(?:1[0-9])|(?:2[0-4]))" 'Check for Hour Beg between 01 and 24
strLt1=strLt1 + "( (?:0[1-9])|(?:[1-5][0-9])|(?:60))" 'Check for Min Beg between 01 and 60
strLt1=strLt1 + "( 00(?:(?:0[1-9])|(?:[1-5][0-9])|(?:60)))" 'Check for #Min Long between 0001 and 0060 (supposed to separate hours)
strLt1=strLt1 + "( 0[1-9])" 'Check for PC between 01 and 09
strLt1=strLt1 + "( (?:(?:000[1-9])|(?:[1-9][0-9][0-9][0-9])|(?:[0-9][1-9][0-9][0-9])|(?:[0-9][0-9][1-9][0-9])))" 'Check for AVG between 0001 and 9999
strLt1=strLt1 + "( (?:(?:000[1-9])|(?:[1-9][0-9][0-9][0-9])|(?:[0-9][1-9][0-9][0-9])|(?:[0-9][0-9][1-9][0-9])))" 'Check for LOW between 0001 and 9999
strLt1=strLt1 + "( !!)" 'Check for !! separator

'Checks for second column
strLt2="(?:(?:" 'Set up for allowing for all blank second column
strLt2=strLt2 + "( (?:" + strOpDate + "))" 'Check date
strLt2=strLt2 + "( (?:0[1-9])|(?:1[0-9])|(?:2[0-4]))" 'Check for Hour Beg between 01 and 24
strLt2=strLt2 + "( (?:0[1-9])|(?:[1-5][0-9])|(?:60))" 'Check for Min Beg between 01 and 60
strLt2=strLt2 + "( 00(?:(?:0[1-9])|(?:[1-5][0-9])|(?:60)))" 'Check for #Min Long between 0001 and 0060 (supposed to separate hours)
strLt2=strLt2 + "( 0[1-9])" 'Check for PC between 01 and 09
strLt2=strLt2 + "( (?:(?:000[1-9])|(?:[1-9][0-9][0-9][0-9])|(?:[0-9][1-9][0-9][0-9])|(?:[0-9][0-9][1-9][0-9])))" 'Check for AVG between 0001 and 9999
strLt2=strLt2 + "( (?:(?:000[1-9])|(?:[1-9][0-9][0-9][0-9])|(?:[0-9][1-9][0-9][0-9])|(?:[0-9][0-9][1-9][0-9])))" 'Check for LOW between 0001 and 9999
strLt2=strLt2 + ")|(?: {0,36}\r\n))" 'Finish off allowing for all blank second column

strLt = strLt1 + strLt2

strPattern=strLt

reLine1.Pattern=strPattern

reLine1.Global=true

reLine1.IgnoreCase=false

reLine1.Multiline=false

retValue=reLine1.Test(strTest)

set Matches=reLine1.Execute(strTest)


document.write(&quot;Results = &quot; & retValue & &quot;<BR>&quot;)

For x=0 to Matches.count-1
if Matches.count<>0 then
For y=0 to Matches(x).SubMatches.count
if SubMatches.count<>0 then
document.write(Matches(x).SubMatches(y) + &quot;<BR>&quot;)
end if
next
end if
next

[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top