PC Review


Reply
Thread Tools Rate Thread

Best practice for for regex and match objects

 
 
jg
Guest
Posts: n/a
 
      18th Aug 2005
If I need to reuse regeex pattern or let non dotnet com client to reuse the
pattern to match against different strings, what is the best way?
How should I free up the resources held by regex?

Right now, I am leaning towards this way

Private Dim RegexCollection as New Microsoft.VisualBasic.Collection()
Private Function makekey(ByVal strPrefx As String) As String

return strPrefx + ToString(Microsoft.VisualBasic.DateAndTime.Timer) +
ToString(Rnd())

End Function

Public function getRegex(strPattern As String, ByRef strKey as String) As
Object ' leaning to use the key to deal with collection

strKey = makekey("regex")

RegexCollection .add(New Regex(strPattern), strKey)

return RegexCollection (strKey)

End Function

Public Function free_RegexObj(ByRef myobj As Object, ByRef mykey As
String)
Try
RegexCollection .Remove(mykey)
myobj.destroy()
mykey = Nothing
Return 0
Catch ex As Exception
Return -1
End Try
End Function

Public function getMatch(str2search As String, ioffset As Integer,
strRegexkey as String, byRef strRegexObj as Object,
ByRef iFoundPos as Integer. ByRef iFoundLen as integer) as integer
.................

' if found return 1 and....
....

' otherwise
return -1
End Function


Is there a better way?


 
Reply With Quote
 
 
 
 
jg
Guest
Posts: n/a
 
      18th Aug 2005
oops I posted to wrong group in terms of the code being vb. sorry!

"jg" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> If I need to reuse regeex pattern or let non dotnet com client to reuse
> the pattern to match against different strings, what is the best way?
> How should I free up the resources held by regex?
>
> Right now, I am leaning towards this way
>
> Private Dim RegexCollection as New Microsoft.VisualBasic.Collection()
> Private Function makekey(ByVal strPrefx As String) As String
>
> return strPrefx + ToString(Microsoft.VisualBasic.DateAndTime.Timer) +
> ToString(Rnd())
>
> End Function
>
> Public function getRegex(strPattern As String, ByRef strKey as String) As
> Object ' leaning to use the key to deal with collection
>
> strKey = makekey("regex")
>
> RegexCollection .add(New Regex(strPattern), strKey)
>
> return RegexCollection (strKey)
>
> End Function
>
> Public Function free_RegexObj(ByRef myobj As Object, ByRef mykey As
> String)
> Try
> RegexCollection .Remove(mykey)
> myobj.destroy()
> mykey = Nothing
> Return 0
> Catch ex As Exception
> Return -1
> End Try
> End Function
>
> Public function getMatch(str2search As String, ioffset As Integer,
> strRegexkey as String, byRef strRegexObj as Object,
> ByRef iFoundPos as Integer. ByRef iFoundLen as integer) as integer
> .................
>
> ' if found return 1 and....
> ....
>
> ' otherwise
> return -1
> End Function
>
>
> Is there a better way?
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Stop Regex.Match(string, int) If First Character Doesn't Match jehugaleahsa@gmail.com Microsoft C# .NET 2 24th May 2009 01:22 AM
Stop Regex.Match(string, int) If First Character Doesn't Match jehugaleahsa@gmail.com Microsoft C# .NET 0 24th May 2009 12:52 AM
Regex match help. match exactly 4 digit numbers gnewsaccess Microsoft VB .NET 1 27th Dec 2008 01:12 AM
Best practice for saving objects owned by objects BobRoyAce Microsoft Dot NET Framework Forms 1 5th Mar 2008 11:34 AM
Best practice for for regex and match objects jg Microsoft C# .NET 0 18th Aug 2005 04:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:41 AM.