[Mono-list] [PATCH] System.Text.RegularExpressions won't DTRT if you re-use patterns

Juli Mallett jmallett@FreeBSD.ORG
Tue, 30 Jul 2002 07:40:41 -0700


Hi,

Currently in the Regex code, there is factory caching code, however things
like grouping need evaluated each time the Regex is constructed, the most
simple/obvious solution is to move that code out of the section that runs
only when there is no cached item in existence.  This happens when one
constructs more than one Regex with the same pattern and the same options
and e.g. tries to use $1 in Replace().  Example code which throws bogus
exception would be something like:

Foo = Regex.Replace(Foo, @"(.*)", "$1");
// Here we get bogus exception
Foo = Regex.Replace(Foo, @"(.*)", "$1");

More or less.

Here's a diff:

http://toxic.magnesium.net/~flata/dump/Regex-factorycache-eval.diff

Thanks,
juli.
-- 
Juli Mallett <jmallett@FreeBSD.org>       | FreeBSD: The Power To Serve
Will break world for fulltime employment. | finger jmallett@FreeBSD.org