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

http://regex101.com/r/rn5ee6

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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -