Skip to main content

Regexp Snippets

Guard Clause to test if string is only whitespace else return

if (!/\S/.test(str: string) return

Mutate String.prototype to add own chain function to decode hex escape sequence BACK into string

String.prototype.decodeEscapeSequence = function () {
return this.replace(/\\x([0-9A-Fa-f]{2})/g, function () {
return String.fromCharCode(parseInt(arguments[1], 16))
})
}

let JS interpreter eval and escape things for you - TEST THIS - BREAKS for invalid escape sequences?!

const escapedString = eval('"' + unescapedStr + '"')

References