473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

need help with regular expressions wrapper function

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?

Oct 2 '06 #1
2 2440
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

%>

Oct 2 '06 #2

"mike" <mi*************@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr 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

%>

Oct 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dmbkiwi | last post by:
I have a problem. I have written a python based theme for a linux app called superkaramba, which is effectively an engine for desktop applets that utilises python as its theming language. The...
21
by: google | last post by:
I'm trying to implement something that would speed up data entry. I'd like to be able to take a string, and increment ONLY the right-most numerical characters by one. The type structure of the...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
4
by: LBC | last post by:
I just stumbled across Regular Expressions and am having problems figuring out how to do the following: strText = "~dc000038~ + ~fa231011~ + ~rs000923~" I would like to strip out all the text...
8
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and I need to parse strings that look similar to the one below. All 5 rows will make up one string. I have a form where a use can copy/paste data like what you...
2
by: news.microsoft.com | last post by:
I need help design a reg exp. I am parsing an html file to get the input values, here is one example <input VALUE="Staff Writer" size=60 type="text" name="author"> Can I grab the value "Staff...
3
by: Chris | last post by:
Hi everyone, I'm trying to parse through the contents of some text files with regular expressions, but am new to regular expressions and how to use them in VB.net. I'm pretty sure that the...
2
by: comp.lang.php | last post by:
I am trying to replace within the HTML string $html the following: With Where I'm replacing "action=move_image" with "action=<?= $_REQUEST ?>"
47
by: Henning_Thornblad | last post by:
What can be the cause of the large difference between re.search and grep? This script takes about 5 min to run on my computer: #!/usr/bin/env python import re row="" for a in range(156000):...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.