Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

Best practice for for regex and match objects

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jg - 18 Aug 2005 04:23 GMT
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?
jg - 18 Aug 2005 04:26 GMT
oops I posted to wrong group in terms of the code being vb.  sorry!

> 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?
[quoted text clipped - 46 lines]
>
> Is there a better way?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.