[Home] >  String >  Unescape HTML special characters

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, '"');