Regular Expressions 101

Community Patterns

Remove GO and split for batch SQL text

1

Regular Expression
ECMAScript (JavaScript)

/
(?:\s|\r)+GO\s*(?:\r|\n)
/
g

Description

Useful for when you need to convert a T-SQL MSSMS Server batch into individual SQL requests by removing the GO between them.

e.g.

Dim SQLBatches As String() = Regex.Split(text, "(?:\s|\r|\n)+GO\s*(?:\r|\n)", RegexOptions.IgnoreCase)

Submitted by SarahC - 9 years ago