473,378 Members | 1,067 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,378 software developers and data experts.

Regex internal caching or what?

Hello!

In my application I have a need for using a regular expression now and then.
Often the same regular expression must be used multiple times. For
performance reasons I use the RegexOptions.Compiled when I instantiate it.
It must be obvious that it takes some time to instantiate such an object.

My question is, does the Regex instantiation somehow deal with some caching
internally so instantiating a Regex object multiple times having the same
expression as the first argument for the constructor is quite efficient or
do I need to create my own caching functionality?
Best regards,

Henrik Dahl
May 1 '07 #1
4 2153
You can compile Regular Expression sinto an assembly if you like.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Henrik Dahl" <He********@community.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hello!

In my application I have a need for using a regular expression now and
then. Often the same regular expression must be used multiple times. For
performance reasons I use the RegexOptions.Compiled when I instantiate it.
It must be obvious that it takes some time to instantiate such an object.

My question is, does the Regex instantiation somehow deal with some
caching internally so instantiating a Regex object multiple times having
the same expression as the first argument for the constructor is quite
efficient or do I need to create my own caching functionality?
Best regards,

Henrik Dahl


May 1 '07 #2

Interestingly, Regex has the funcionality to do internal caching, but
it apparently is not exposed to the caller.

When you use one of the static methods like Regex.Match and
Regex.Split it will use a private constructor Regex(pattern, options,
cache) and specify true for cache. However, the public constructors
all force false for cache.

So you should have your own caching mechanism if testing demonstrates
that caching would be beneficial in your application.

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Tue, 1 May 2007 11:59:05 +0200, "Henrik Dahl"
<He********@community.nospamwrote:
>Hello!

In my application I have a need for using a regular expression now and then.
Often the same regular expression must be used multiple times. For
performance reasons I use the RegexOptions.Compiled when I instantiate it.
It must be obvious that it takes some time to instantiate such an object.

My question is, does the Regex instantiation somehow deal with some caching
internally so instantiating a Regex object multiple times having the same
expression as the first argument for the constructor is quite efficient or
do I need to create my own caching functionality?
Best regards,

Henrik Dahl
May 1 '07 #3
Hi Henrik,

The caching behavior of RegEx got changed from .NET 1.1 to .NET 2.0. There
are basically 2 changes:
#1, The 2.0 Regex class no longer has an unbounded cache size.
#2, The 2.0 Regex class no longer caches parsed regular expressions created
by Regex instance methods, it only caches regular expressions created by
Regex static methods, such as Regex.Match, Regex.Split.

Please refer to the blog entry below for more details:
"Regex Class Caching Changes between .NET Framework 1.1 and .NET Framework
2.0 [Josh Free]"
http://blogs.msdn.com/bclteam/archiv...aching-changes
-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx

Regarding the semantics and performance issue for RegexOptions.Compiled,
please refer to the articles below:
"Regular Expression performance [David Gutierrez]"
http://blogs.msdn.com/bclteam/archiv...12/256783.aspx
"Regular Expression Compilation" section of link below:
http://msdn.microsoft.com/msdnmag/is...RInsideOut/#S7

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
May 2 '07 #4
Jeffrey Tan,

Please allow me to express my recognition of your very precise and
constructive answer.
Best regards,

Henrik Dahl

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comskrev i en meddelelse
news:pO**************@TK2MSFTNGHUB02.phx.gbl...
Hi Henrik,

The caching behavior of RegEx got changed from .NET 1.1 to .NET 2.0. There
are basically 2 changes:
#1, The 2.0 Regex class no longer has an unbounded cache size.
#2, The 2.0 Regex class no longer caches parsed regular expressions
created
by Regex instance methods, it only caches regular expressions created by
Regex static methods, such as Regex.Match, Regex.Split.

Please refer to the blog entry below for more details:
"Regex Class Caching Changes between .NET Framework 1.1 and .NET Framework
2.0 [Josh Free]"
http://blogs.msdn.com/bclteam/archiv...aching-changes
-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx

Regarding the semantics and performance issue for RegexOptions.Compiled,
please refer to the articles below:
"Regular Expression performance [David Gutierrez]"
http://blogs.msdn.com/bclteam/archiv...12/256783.aspx
"Regular Expression Compilation" section of link below:
http://msdn.microsoft.com/msdnmag/is...RInsideOut/#S7

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.


May 2 '07 #5

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

Similar topics

3
by: Day Of The Eagle | last post by:
Jeff_Relf wrote: > ...yet you don't even know what RegEx is. > I'm looking at the source code for mono's Regex implementation right now. You can download that source here ( use the class...
14
by: jumpstart | last post by:
I need a RegEx to validate INTERNATIONAL PHONE NUMBRES. Thanks, JS
7
by: alphatan | last post by:
Is there relative source or document for this purpose? I've searched the index of "Mastering Regular Expression", but cannot get the useful information for C. Thanks in advanced. -- Learning...
4
by: ilPostino | last post by:
hi, I'm trying to write my own code-dom because I don't like the ms one ;-) I want to look for this expression, ( using someword; ) but I can only figure out basic things like searching for...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
17
by: garrickp | last post by:
While creating a log parser for fairly large logs, we have run into an issue where the time to process was relatively unacceptable (upwards of 5 minutes for 1-2 million lines of logs). In contrast,...
3
by: hendedav | last post by:
Gang, I have been working on this for a few hours and am frustrated beyond all extent. I have tried to research this on the web as well with no success. I am trying to match certain contents...
1
by: jmacduff | last post by:
I have a performance issue related to regular expressions and caching , hopefully someone can point me in the right direction? I have a asp.net web service that is called several million times a...
4
n8kindt
by: n8kindt | last post by:
i'm trying to allow my website to use a http://ourdomain.com/fname.lname/ format. i am fairly certain my regex syntax is correct. here's what i have: <IfModule mod_rewrite.c> RewriteEngine on...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.