RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find SQL Batch parser (isql-like)
Expression
(?:^.*\r*\n*)*?(?:(?=^\s*GO\s*$)|$)
Description
simulates sql batch parsing behavior of isql.exe given an inputfile. The regex matches correspond to sql batches (arbitrary text) which are separated by the GO keyword on a line by itself, but not including this GO keyword. Make sure multiline switches are enabled. (One could use this regex to loop over the matches, executing one sql batch at a time, esp in situations where a Split() function is unavailable).
Matches
[input form not adequate for sufficient matching example]
Non-Matches
[input form not adequate for sufficient matching example]
Author Rating: Not yet rated. Jon Schoning
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: The GO issue
Name: Steve Owens
Date: 12/18/2007 8:56:58 AM
Comment:
I just so happens I had to try and fix a local program that was trying to parse T-SQL text into batches. The C# code looked for a GO, then took all the text leading up to it and sent it to SQL for proecessing. Now, I am NOT fluent in RegEx, but I came up with this: ^\s*GO(\s*|\s*--+.*)$ The issue I tried to handle was that GO is allowed to have a "--" comment after it. That, and our original RegEx failed if GO was the last significant line in the file! Puzzled over that for quite a while before realizing it was a RegEx problem. The issue I was NOT equipped to handle was if GO is on a line by itself within a multi-line comment block, /* ... */.


Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials