ruby - replace every occurrence that is unquoted -


i'm trying write regex in vim replace every occurrence of true 't' , false 'f' in sql file. complicate this, shouldn't replace true or false when occur anywhere inside quotes.

i'm using following regex works:

%s/\v^(([^'"]*)|(.*('.*'|".*").*)*)\zs((t)rue|(f)alse)/'\6\7'/ #       no qts or number of qts   \6     \7 

but 1 small problem: replaces 1 set of trues , falses per run. e.g. (matches highlighted in bold):

insert pages values (42, null, 'string', true, '', null, true, false, 1); insert pages values (42, null, 'string', true, null, true, false, 1); insert pages values (42, null, true, '', null, true, false, 1); insert pages values (42, null, true, null, true, false, 1);

i've tried sorts of stuff, , i've searched internet can't find anything, i'm stuck. there regex wizards here know how can fix this?

a vim or ruby solution ideal, general solution helpful well.

fyi: rake task pulls remote pg database local sqlite3 database.

using vim substitute along negative look-behinds , negative look-aheads, along taking inspiration current attempt:

%s/\([\s"']\)\@<!\(\(t\)rue\|\(\(f\)alse\)\)\([\s"']\)\@!/'\3\5'/g 

the following

insert pages values (42, null, 'string true', true, '', null, true, false, 1); insert pages values (42, null, "string false", true,     null, true, false, 1); insert pages values (42, null,           true, '', null, true, false, 1); insert pages values (42, null,           true,     null, true, false, 1); 

turns into:

insert pages values (42, null, 'string true', 't', '', null, 't', 'f', 1); insert pages values (42, null, "string false", 't',     null, 't', 'f', 1); insert pages values (42, null,           't', '', null, 't', 'f', 1); insert pages values (42, null,           't',     null, 't', 'f', 1); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -