I am currently working on some Python snippets for VSCode using JavaScript regular expressions and I'd like to have one like :
Given
var1, var2, var3
Produce
self.var1 = var1
self.var2 = var2
self.var3 = var3
I currently know how to replace commas with line jump but not how to replace each word with another string. I'm pretty bad at regular expressions so it doesn't help. I think I'll need something that does the following :
var1, var2 -> self.var1 = var1, self.var2 = var2
Thanks for your help
Edit :
From suggestions in comments I tried this : /(.*,)/self.$0 = $0/
It obviously doesn't work for several reasons : it matches all strings up to the last comma. VSCode doesn't give access to "\w" but i don't see how it would help.
Other thing I tested that couldn't work either since I'm looking for duplicating each of the words : /(.*)/self.$0 = $0/
And since I didn't post it, here is the comme replacement by a new line :
/[,]/\n/g
Edit2 (updated) :
From comment suggestions I tried : /(.*?)(?:, |$)/self.$1 = $1\n/g
which leads to almost perfect result :
toto, titi, tata
leads to
self.toto = toto
self.titi = titi
self.tata = tata
self. =