Skip to main content

Unescape HTML special characters

JavaScript version

const unescape = (str) =>
str
.replace(/&/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&#0*39;/g, "'")
.replace(/&quot;/g, '"');

TypeScript version

const unescape = (str: string): string =>
str
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&#0*39;/g, "'")
.replace(/&quot;/g, '"');

Comments