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

Regular Expression Multiple Match per string not working

Status
Not open for further replies.

brettz

Programmer
Jul 18, 2002
42
US
I'm trying to make a RegExp match for any text that is in between '<<<' and '>>>' However, I am unable to do this unless there is a carriage return within the string being evaluated by the Regular Expression object. For example, if I evaluate the following string, I will only get a match on the first instance of text between '<<<' and '>>>' per line:

Type: <<<Type>>>
If Type = &quot;Professional Liability&quot; then enter <<<Occurance>>> and <<<Aggregate>>>

I get a match for 'Type' and 'Occurance', but NOT for 'Aggregate'

Here is the code I am using:

'Create Regualar Expression Object
Set objRE = New RegExp
'objRE.Pattern = &quot;&#60;&#60;&#60;[\s\S].[^>]*&#62;&#62;&#62;&quot; 'to match <<< >>> tags and contents
objRE.Global = True
'Get all matches for any text within special character Set objMatches = objRE.Execute(description)

I can't figure out why I only get one match per line. I have spent hours trying to figure this out and have researched several web sites regarding RegExp thorougly.

Please advise...I would greatly appreciate any help or ideas.

Thanks,

-Brett
 
This is working for me with: VBScript Version 5.5.7426

So you may only need to upgrade your 'minor' version to .5 (whatever that means) :)

What are your apps doing that IE6 breaks them??

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
This version should work for your current scripting version - it won't work across multiple lines though, you'd have to read in line by line or something..
Code:
Dim RegX, Match, matchesColl, sPattern, sReplaceWith, sString
    
    sPattern = &quot;<<<([^<]+)>>>&quot;
    sString = &quot;Type: <<<Type>>>&quot; & &quot;If Type <<<Occurance>>> and <<<Aggregate>>>&quot;

    Set RegX = NEW RegExp
    RegX.Pattern = sPattern
    RegX.Global = True
    RegX.IgnoreCase = True
   ' RegX.MultiLine = True
    
    Set matchesColl = RegX.Execute(sString)
    
    Response.write(&quot;Searching: &quot; & Server.HTMLEncode(sString) & &quot;<br>&quot;)
    For Each Match in matchesColl
      Response.Write(&quot;Match: &quot; & Server.HTMLEncode(Match) & &quot;, Match.subMatches(0): &quot; & Match.subMatches(0) & &quot;<br>&quot;)
    Next

The other one is better however - see if you can upgrade.

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top