Monday, February 19, 2007

Note to self - Regex for converting table text extract into the insert statement (or whatever)

Again, just in order to have it somewhere for myself and not writing from scratch next time. Input Data:
0 None 1 Critical 2 Error 4 Warning 8 Information 16 Verbose 256 Start 512 Stop 1024 Suspend 2048 Resume 4096 Transfer
Regex (set dot to match a new line): (\d+)(\s+)(\w+) Replace (sample): INSERT INTO [C000].[CMN_MESSAGE_TYPE] (MESSAGE_TYPE_SID, NAME) VALUES ($1,'$3')\r\n Sample output: INSERT INTO [C000].[CMN_MESSAGE_TYPE] (MESSAGE_TYPE_SID, NAME) VALUES (0,'None') INSERT INTO [C000].[CMN_MESSAGE_TYPE] (MESSAGE_TYPE_SID, NAME) VALUES (1,'Critical') INSERT INTO [C000].[CMN_MESSAGE_TYPE] (MESSAGE_TYPE_SID, NAME) VALUES (2,'Error') INSERT INTO [C000].[CMN_MESSAGE_TYPE] (MESSAGE_TYPE_SID, NAME) VALUES (4,'Warning')
Post a Comment