fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var str = @"CREATE TABLE [dbo].[Event](
  10. [ID] [int] IDENTITY(1,1) NOT NULL,
  11. [Date Started] [datetime] NOT NULL,
  12. [StartTime] [time](7) NOT NULL,
  13. [Description] [nvarchar](250) NULL,
  14. [AudioLocation] [nvarchar](max) NOT NULL,
  15. [PlayerLocation] [nvarchar](max) NOT NULL,
  16. CONSTRAINT [PK_dbo.Event] PRIMARY KEY CLUSTERED";
  17. var result = Regex.Replace(str, @"\[(\w+)]|\[([^]]+)]", m => m.Groups[1].Success ? m.Groups[1].Value : $"\"{m.Groups[2].Value}\"");
  18. Console.WriteLine(result);
  19. }
  20. }
Success #stdin #stdout 0.1s 29624KB
stdin
Standard input is empty
stdout
CREATE TABLE dbo.Event(
    ID int IDENTITY(1,1) NOT NULL,
    "Date Started" datetime NOT NULL,
    StartTime time(7) NOT NULL,
    Description nvarchar(250) NULL,
    AudioLocation nvarchar(max) NOT NULL,
    PlayerLocation nvarchar(max) NOT NULL,
 CONSTRAINT "PK_dbo.Event" PRIMARY KEY CLUSTERED