regex - Smart conversion of single to double quotes in Ruby -
problem
in source file, have large number of strings.ome interpolation, special symbols , neither.
i trying work out if can replace single quotes double quotes whilst converting escaped single quote characters. run conversion on 1 or more source code files.
example - code
imagine following code:
def myfunc(var, var2 = 'abc') s = 'something' puts 'a simple string' puts 'string escaped quote \' in it' x = "nasty #{interpolated}" + s + ' , single quote combo' puts "my #{var}" end
example - result
i turn this:
def myfunc(var, var2 = "abc") s = "something" puts "a simple string" puts "string escaped quote ' in it" x = "nasty #{interpolated}" + s + " , single quote combo" puts "my #{var}" end
if has ideas i'd grateful!
you want negative behind (?<!)
operator:
regex
(?<!\)'
demo
explanation
- you want replace single quote not preceded backslash.
- don't forget find , replace of
\'
'
there more
for use case, if it's simple use case, ruby parser perform better.
Comments
Post a Comment