Skip to content

Instantly share code, notes, and snippets.

@muxueqz
Created August 17, 2017 14:02
Show Gist options
  • Save muxueqz/0f0c21dda0c98fef802e462f96b809b7 to your computer and use it in GitHub Desktop.
Save muxueqz/0f0c21dda0c98fef802e462f96b809b7 to your computer and use it in GitHub Desktop.
function unescape(str)
str = string.gsub( str, '&lt;', '<' )
str = string.gsub( str, '&gt;', '>' )
str = string.gsub( str, '&quot;', '"' )
str = string.gsub( str, '&apos;', "'" )
str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end )
str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end )
str = string.gsub( str, '&amp;', '&' ) -- Be sure to do this after all others
return str
end
print(unescape("&#34;Hello&quot; &apos;World&#39;")) --> "Hello" 'World'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment