Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > need help with regular expressions wrapper function

Reply
Thread Tools

need help with regular expressions wrapper function

 
 
mike
Guest
Posts: n/a
 
      10-02-2006
Hello,

I'm trying to write a function to return submatches. I want to do this
because I want to run a match on matches of matches of yet other
matches, so it seemed to me it would be easier to work with if there
was one line of code that would return a collection or array of
matches. Here's what I got:

<%
Dim objRegExp
Set objRegExp = New RegExp
Dim objMatches, objMatch

Set submatches = getsubmatches("this should hopefully match and print
eight words", "(\w)", TRUE, TRUE)

For i = 0 To submatches.Count - 1
response.write "<br>" & submatches(i)
Next


Function getsubmatches(strText, pattern, isGlobal, ignoreCase)
Dim data

'Set our pattern
objRegExp.Pattern = pattern
objRegExp.IgnoreCase = ignoreCase
objRegExp.Global = isGlobal

For Each objMatch in objRegExp.Execute(strText)
getsubmatches = objMatch.SubMatches
Next
End Function

%>

I get:
Microsoft VBScript runtime (0x800A01C2)
Wrong number of arguments or invalid property assignment
/getsubmatches.asp, line 22

thats this line: "getsubmatches = objMatch.SubMatches"

Can anyone help me write this correctly?

 
Reply With Quote
 
 
 
 
mike
Guest
Posts: n/a
 
      10-02-2006
Heres my source. I don't understand why the text function works but
the object one does not. Can anyone help me?

regards,
Mike

<%

'this one works
response.write "<br>" & getSubmatchesText("this should hopefully match
and print eight words", "(\w)", TRUE, TRUE)

'this one doesn't work
Set submatches = getsubmatchesObject("this should hopefully match and
print eight words", "(\w)", TRUE, TRUE)
For i = 0 To submatches.Count - 1
response.write "<br>" & submatches(i)
Next


Function getsubmatchesObject(strText, pattern, isGlobal, ignoreCase)
Dim objRegExp
Set objRegExp = New RegExp
Dim objMatches, objMatch

'Set our pattern
objRegExp.Pattern = pattern
objRegExp.IgnoreCase = ignoreCase
objRegExp.Global = isGlobal

For Each objMatch in objRegExp.Execute(strText)
getsubmatchesObject = objMatch.SubMatches
Next
End Function


Function getSubmatchesText(strText, pattern, isGlobal, ignoreCase)
Dim objRegExp
Set objRegExp = New RegExp
Dim objMatches, objMatch

Dim data

'Set our pattern
objRegExp.Pattern = pattern
objRegExp.IgnoreCase = ignoreCase
objRegExp.Global = isGlobal

For Each objMatch in objRegExp.Execute(strText)
For i = 0 To objMatch.submatches.Count - 1
data = data & objMatch.SubMatches(i)
Next
Next
getSubmatchesText = data
End Function

%>

 
Reply With Quote
 
 
 
 
Anthony Jones
Guest
Posts: n/a
 
      10-03-2006

"mike" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Heres my source. I don't understand why the text function works but
> the object one does not. Can anyone help me?
>
> regards,
> Mike
>
> <%
>
> 'this one works
> response.write "<br>" & getSubmatchesText("this should hopefully match
> and print eight words", "(\w)", TRUE, TRUE)
>
> 'this one doesn't work
> Set submatches = getsubmatchesObject("this should hopefully match and
> print eight words", "(\w)", TRUE, TRUE)
> For i = 0 To submatches.Count - 1
> response.write "<br>" & submatches(i)
> Next
>
>
> Function getsubmatchesObject(strText, pattern, isGlobal, ignoreCase)
> Dim objRegExp
> Set objRegExp = New RegExp
> Dim objMatches, objMatch
>
> 'Set our pattern
> objRegExp.Pattern = pattern
> objRegExp.IgnoreCase = ignoreCase
> objRegExp.Global = isGlobal
>
> For Each objMatch in objRegExp.Execute(strText)
> getsubmatchesObject = objMatch.SubMatches


A SubMatches is an object hence the line above should use a Set

> Next
> End Function
>


This code (when the set is applied) will return a submatches object
containing a single value which is the last word in the string. The
function doesn't really make any sense. It seems to me what might make more
sense is simply to return the resulting object from the execute method.


>
> Function getSubmatchesText(strText, pattern, isGlobal, ignoreCase)
> Dim objRegExp
> Set objRegExp = New RegExp
> Dim objMatches, objMatch
>
> Dim data
>
> 'Set our pattern
> objRegExp.Pattern = pattern
> objRegExp.IgnoreCase = ignoreCase
> objRegExp.Global = isGlobal
>
> For Each objMatch in objRegExp.Execute(strText)
> For i = 0 To objMatch.submatches.Count - 1
> data = data & objMatch.SubMatches(i)
> Next
> Next
> getSubmatchesText = data
> End Function
>
> %>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with regular expressions tsahiasher@gmail.com Perl Misc 4 12-25-2007 04:09 PM
More questions about search function on regular expressions .Net Sports Javascript 2 05-08-2007 10:39 PM
Add custom regular expressions to the validation list of available expressions Jay Douglas ASP .Net 0 08-15-2003 10:19 PM
Re: Help with regular expressions. Chris R. Timmons ASP .Net 0 07-04-2003 10:49 PM
Re: Help with regular expressions. David Waz... ASP .Net 0 07-04-2003 08:59 PM



Advertisments