Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8819263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:18:45+00:00 2026-06-14T05:18:45+00:00

All, I have a series of SQL statements seperated in a string by ‘GO’

  • 0

All, I have a series of SQL statements seperated in a string by ‘GO’ (case insensitive, so ‘Go’, ‘go’ et al. are also valid). If I have a statement like

string str = "INSERT INTO People \r\n" + 
                "VALUES (3, 'Gandalf', 'The Gray'); \r\nGO\r\n" + 
             "INSERT INTO People \r\n" + 
                "VALUES (4, 'Legolas', 'Camus'); \r\nGO";

I want to avoid a match on the ‘go’ in ‘Legolas’. To do this I devised a regular expression in LINQPad with both negative lookahead and positive lookbehind, and have

string str = "INSERT INTO People \r\n" + 
                "VALUES (3, 'Gandalf', 'The Gray'); \r\nGO\r\n" + 
             "INSERT INTO People \r\n" + 
                "VALUES (4, 'Legolas', 'Camus'); \r\nGO";
Regex regGo = new Regex(@"(?<=\b)(?i)GO(?!\w+)");
MatchCollection matches = regGo.Matches(str);
foreach (Match m in matches)
{
    m.Dump();
}

Which does what I want, namely, it only matches a ‘GO’ (of any case) when it is a new ‘GO’ and not followed by anything. This works in LINQPad – i.e. returns the required result; but not in my C# app.

Why the descrepancy and what am I doing wrong?

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:18:47+00:00Added an answer on June 14, 2026 at 5:18 am

    I was able to get your example to work in both LinqPad and a Console app.

    A suggestion to simplify your regex and avoid using look behind and look ahead would be to use word boundaries like this:

    \b(?i)GO\b

    This will accomplish the same result and be a little more readable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have a series of product pages and all I'd like to do
I'm trying to emulate a SQL IN statement on a series of SQL LIKE
I'm trying to work out an SQL statement for MySQL. I have a series
I have a series of T-SQL DELETE FROM TABLE and INSERT statements to run.
I am processing a series of points which all have the same Y value,
I am creating a series of UserControls that all have some similar business logic.
need a quick help here. I have a series of hyperlinks all with the
I have a MySQL Table that looks like this: The SQL to create the
I have a series of calculation times in a DB2 SQL DB that are
I'm using SQL Server 2005. I have a series of product and pricing tables

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.