Keith, the escape character for a curly-brace is another curly brace.
So, to take your example below, you could do this (assuming you want
string.format to preserve the curly brackets around the 14):

(?<DocID>\\d{{14}})\\|(?:[\\w\\s]+\\|){0}(?<LineNum>\\d+)\\|.*

Note that I have turned (for this example) the slashes into
double-slashes, to preserve their 'escape' quality for regex also.

Regards,
Kit

-----Original Message-----


From: Wedinger, Keith [mailto:[EMAIL PROTECTED] 
Sent: Monday, March 24, 2003 12:09 PM
To: [EMAIL PROTECTED]

I have the following regular expression that is capturing two fields.
Notice the {0} near the middle of the expression.  I want to replace {0}
with a decimal number using String.Format().  Unfortunately,
String.Format()
is getting confused about other {}'s that occur in the regular
expression.
I tried escaping the curly braces but C# complained that the resultant
string was an invalid escape sequence.

I could bust up the string below into multiple strings and then do
multiple
StringBuilder Append calls to build it up but that seems a bit ugly to
me.

Is there a way to pass a regular expression with curly-braces such that
Format() will do its thing properly (i.e. won't get confused about
curly-braces that are really part of the regular expression and should
not
be touched)?

(?<DocID>\d{14})\|(?:[\w\s]+\|){0}(?<LineNum>\d+)\|.*

J. Keith Wedinger
Senior Software Developer
Sterling Commerce

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com
You may be interested in Guerrilla .NET, 24 March 2003, in London and
Boston
http://www.develop.com/courses/gdotnet

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
You may be interested in Guerrilla .NET, 24 March 2003, in London and Boston
http://www.develop.com/courses/gdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to