Im an intern at a software company, and I think I'm way over my head.
I need a script that can read and parse a text file (easy part, that I
know)
but I need my script to extract text between two delimiters that i can
specify.

is it possible to do this with regular expressions?

thanks in advance

Re: New to scripting, need a lil help by mr_unreliable

mr_unreliable
Mon Jun 18 12:57:03 CDT 2007

Yes, it's possible with regexp.

It is also possible, using the plain 'ole split function
-- and maybe a little more transparent.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)


drk360@hotmail.com wrote:
> Im an intern at a software company, and I think I'm way over my head.
> I need a script that can read and parse a text file (easy part, that I
> know)
> but I need my script to extract text between two delimiters that i can
> specify.
>
> is it possible to do this with regular expressions?
>
> thanks in advance
>

Re: New to scripting, need a lil help by ekkehard

ekkehard
Mon Jun 18 13:04:29 CDT 2007

drk360@hotmail.com schrieb:
> Im an intern at a software company, and I think I'm way over my head.
> I need a script that can read and parse a text file (easy part, that I
> know)
> but I need my script to extract text between two delimiters that i can
> specify.
>
> is it possible to do this with regular expressions?
>
> thanks in advance
>
Yes:

Dim aDelims : aDelims = Array( _
Array( False, "%" , "%" , New RegExp ) _
, Array( False, "D" , "D" , New RegExp ) _
, Array( False, "<begin>", "<end>", New RegExp ) _
, Array( True , "(" , ")" , New RegExp ) _
)
Dim aTests : aTests = Array( _
"aaa%1234%aaaD5678D<begin>90123<end>aaa(4567)aaa" _
, "aaa%1234%aaaD5678D<BEGIN>90123<END>aaa(4567)aaa" _
, "aaa%1234%aaa%5678%%90123%aaa%4567%aaa" _
)
Dim aDelim, sTest, oMTS, oMT, sSM

For Each aDelim In aDelims
If aDelim( 0 ) Then
aDelim( 3 ).Pattern = "\" + aDelim( 1 ) + "(.*?)\" + aDelim( 2 )
Else
aDelim( 3 ).Pattern = "" + aDelim( 1 ) + "(.*?)" + aDelim( 2 )
End If
aDelim( 3 ).Global = True
aDelim( 3 ).IgnoreCase = True
Next

For Each sTest In aTests
WScript.Echo "Search:", sTest
For Each aDelim In aDelims
WScript.Echo " Delim:", Join( Array( aDelim( 1 ), aDelim( 2 ) ), " " )
' WScript.Echo " Pat:", aDelim( 3 ).Pattern
Set oMTS = aDelim( 3 ).Execute( sTest )
For Each oMT In oMTS
WScript.Echo " MT:", oMT.Value
For Each sSM In oMT.SubMatches
WScript.Echo " Cut:", sSM
Next
Next
Next
WScript.Echo
Next

The code shows how to set up the RegExps (possible pitfall: metacharacters
like () have to be escaped) and how to gather the results. Add some 'real
world' examples to aTests to see whether your data will be processed correctly;
nested delimiters and/or incomplete pairs will break this approach.

The non greedy collection sub part (.*?) may be optimized to "([^" +
aDelim( 2 ) + "]*)" for (second) delimiter of lenght = 1.


Re: New to scripting, need a lil help by drk360

drk360
Mon Jun 18 15:23:45 CDT 2007

Thank you very much, im gonna try this, looks like what im looking for