473,657 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best practice for for regex and match objects

jg
If I need to reuse regex 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.Visua lBasic.Collecti on()
Private Function makekey(ByVal strPrefx As String) As String

return strPrefx + ToString(Micros oft.VisualBasic .DateAndTime.Ti mer) +
ToString(Rnd())

End Function

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

strKey = makekey("regex" )

RegexCollection .add(New Regex(strPatter n), strKey)

return RegexCollection (strKey)

End Function

Public Function free_RegexObj(B yRef 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(str2se arch 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?

Nov 17 '05 #1
0 1025

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

Similar topics

3
2079
by: Jon Maz | last post by:
Hi All, Am getting frustrated trying to port the following (pretty simple) function to CSharp. The problem is that I'm lousy at Regular Expressions.... //from http://support.microsoft.com/default.aspx?scid=kb;EN-US;246800 function fxnParseIt() { var sInputString = 'asp and database';
20
8091
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex matches are called within a loop (like if or for). E.g. for(int i = 0; i < 10; i++) { Regex r = new Regex();
6
314
by: Frank | last post by:
Hi, I'm beginning to understand regex (regular expressions), but I think there's a better way to do the next thing. I use 2 steps, is it possible to do it in 1 step? <img somestuff src="found.gif" otherstuff> Is it possible to get the index and length of 'found.gif' in 1 regex match? Thanks in advance
2
1722
by: ankit | last post by:
I want to get the start and end of all the patterns mattched in regex. I know I can get it with start() and end() fn of matched objects. But re.search() return the match object of first matching regex in the string. I want all match objects in that string Here is the string : tmplstr = """ ${name}
8
1678
by: jlowery | last post by:
I'm looking through the tools/scripts folder from the python install, trying to get reacquanted with the language. Got a question on the following classfix.py snippet: # This expression doesn't catch *all* class definition headers, # but it's pretty darn close. classexpr = '^\(*class ++\) *( *) *\(\(=.*\)?\):' classprog = regex.compile(classexpr) Since the classexpr isn't a raw string (not r prefix), doesn't the \t
29
2884
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
5
1647
by: Maqsood Ahmed | last post by:
Hello, I am trying to create a Regex object which can match ASCII character 0x05 in a given string. I have written following code to accomplish this: System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("*?", System.Text.RegularExpressions.RegexOptions.Compiled);
2
1538
by: John B | last post by:
I am trying to do a pretty simple pattern match using regex. The pattern is ^(?:(?<Item>.*?)@:@)*$. This should return a match for test123@:@ but does not, instead it never returns when I call Regex.Match, I have to kill the thread. The code is below, The Regulator (some will know it) returns the correct results, I cannot work out why.
4
1797
by: tinkerbarbet | last post by:
Hi I've read around quite a bit about Unicode and python's support for it, and I'm still unclear about how it all fits together in certain scenarios. Can anyone help clarify? * When I say "# -*- coding: utf-8 -*-" and confirm my IDE is saving the source file as UTF-8, do I still need to prefix all the strings constructed in the source with u as in myStr = u"blah", even when those strings contain only ASCII or ISO-8859-1 chars? (It...
0
8384
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8302
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.