I have a string (more precisely a query) where I need to add some characters ("\n") at the end of all words between ''. The problem is that my string algo contains numbers between '', and they should remain unchanged. A simplified version of the beginning of the string follows:
"SELECT CASE WHEN V1 = '1' THEN 'word' WHEN V1 = '3' THEN 'another word' END"
And the desired result with the replacements would be:
"SELECT CASE WHEN V1 = '1' THEN 'word\n' WHEN V1 = '3' THEN 'another word\n' END"
I tried using gsub function, but I couldn`t figure out how to make it work the way I need. If I use:
gsub("' ", "\n' ", string)
The numbers are also replaced. Or if I use:
gsub("[a-z]' ", "\n' ", string)
I end up removing the last letter of the words.
Am I missing an obvious solution here? I`m quite new at programming, so I apreciate some help if possible.