Search code examples
regexnotepad++

Transfer last word of the line to a new line in Notepad++


So I have around 40k lines of INSERT like this:

INSERT INTO dbo.table (something) values ('something') GO

But I want to move the word GO on a new line, using Regex:

   INSERT INTO dbo.table (something) values ('something') 
    
    GO

How can I do this?


Solution

  • Just extract GO and replace it with \nGO.

    Try this one:

    const input = `
    INSERT INTO dbo.table (something) values ('something') GO
    INSERT INTO dbo.table (something) values ('something') GO
    INSERT INTO dbo.table (something) values ('something') GO
    `
    
    const res = input.replace(/(\w+)$/gm, '\n$1')
    console.log(res)