Leticia Esperon Leticia Esperon - 5 months ago 35
Ruby Question

Is is possible to create a string in ruby that keeps escaping characters?

I need to form a user-data script from Ruby so I need all escaping characters to remain. When I do this:

def user_data
sed -i -e '/<Name>loadbalanceServerIP<\/Name>/,/<Value>/s/<Value>[^<]*/<Value>' /home/wowza/conf/Server.xml"

The string removes the \ in the Name tag. If I put two \, it keeps them both. Any suggestion as how to keep the string the same way I wrote it?

Thank you!


You can use the %q delimiter rather than ":

def user_data
     sed -i -e '/<Name>loadbalanceServerIP<\/Name>/,/<Value>/s/<Value>[^<]*/<Value>' /home/wowza/conf/Server.xml]