Hi Shawn The problem is that your compiled regular expression with the options is effectively ignored since ToString() just returns the pattern and what you really are doing is creating and using a new regular expression without any options.
Instead of: sqlSyntax = Regex.Replace(sqlSyntax, declare.ToString(), ""); Use: sqlSyntax = declare.Replace(sqlSyntax, ""); which uses your original expression including the IgnoreCase Cheers Simon -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Hevel, Shawn Sent: 13 April 2006 13:07 To: [email protected] Subject: Re: [ADVANCED-DOTNET] c# and regular expression Eric, I can get the same to happen in Expresso but in DOTNET it doesn't remove the code. That is why I included what my code looks like to see if I've made a syntax error. Can anyone look at the code below and see if it is coded properly. It looks correct to me? Thanks, Shawn Hevel, API, AIT Lead Programmer Analyst Information Technology Department South Carolina Farm Bureau Insurance Companies Phone: (803) 936-4331 Fax: (803) 936-4629 Work Email: [EMAIL PROTECTED] Home Email: [EMAIL PROTECTED] -----Original Message----- From: Eric Means [mailto:[EMAIL PROTECTED] Sent: Friday, April 07, 2006 12:44 PM To: [email protected] Subject: Re: [ADVANCED-DOTNET] c# and regular expression What are you trying to do? When I run that regex in The Regulator it removes the "declare cursors" comment, but leaves everything else alone: \r\n\r\n\r\nDECLARE C1 CURSOR WITH RETURN FOR \r\nSELECT\r\n MAX(EFFECTIVE_DATE) AS EFFECTIVE_DATE\r\nFROM\r\n POLICY_AMENDMENT\r\nWHERE\r\n [EMAIL PROTECTED] AND\r\n TRANSACTION_CODE<>'RNL'\r\n On 4/7/06, Hevel, Shawn <[EMAIL PROTECTED]> wrote: > > I'm trying to do a replace using a regular express. The regular > expression > works in Express but when I use it in C#.NET it doesn't work. Here is the > code listed below: > > > > Regex declare = new Regex(@"(?:--\s*DECLARE\s*CURSOR)(?:S)", > RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline| > RegexOptions.IgnorePatternWhitespace); > > > > sqlSyntax = Regex.Replace(sqlSyntax, declare.ToString(), ""); > > > > Here is the code that I'm searching: > > > > \r\n\r\n-- Declare cursors\r\nDECLARE C1 CURSOR WITH RETURN FOR > \r\nSELECT\r\n MAX(EFFECTIVE_DATE) AS EFFECTIVE_DATE\r\nFROM\r\n > POLICY_AMENDMENT\r\nWHERE\r\n [EMAIL PROTECTED] AND\r\n > TRANSACTION_CODE<>'RNL'\r\n > > > > I've tried the above regex with both the @"(?:--\s*DECLARE\s*CURSOR)(?:S)" > and (?:--\s+DECLARE.*?(?=\\r\\n)) syntax. > > > > Does anything look out of place? > > > > > > Shawn Hevel, API, AIT > Lead Programmer Analyst > Information Technology Department > South Carolina Farm Bureau Insurance Companies > Phone: (803) 936-4331 > Fax: (803) 936-4629 > Work Email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > Home Email: [EMAIL PROTECTED] > > > > > =================================== > This list is hosted by DevelopMentor(r) http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com > -- Eric Means [EMAIL PROTECTED] http://www.randomtree.org/eric/ =================================== This list is hosted by DevelopMentor(r) http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor(r) http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
