Useful Regex for CSV to SQL


2008-03-07 Digg! icurtain Delcious icurtain

As a point of reference

how to convert a comma delimited file to an SQL insert
Assuming your data is the following

'key','value','0'
'key','value','1'

In notepad++ the syntax for search and replace would be as follows:
search: ('[^']+','[^']+','[^']+')
replace: (\1)
syntax varies depending on the flavour of regex

which can then have an insert statement added and...:
insert into table (key_value, value_blah, personal_id)
values
('key','value','0')
('key','value','1')

deleteing columns in Textpad
INSERT INTO "IB_RESOURCE_MESSAGE" (IB_MESSAGE_ID,IB_VALUE,IB_KEY,IB_BUNDLE_ID) VALUES (0,'Welcome #{identity.username}','loginSucceeded',0)

to delete the first value column (1, .... use the following
([0-9]+,
the plus will search for recurring instances of the pattern [0-9]