$_=~s/^\s+|\s+$//g;# remove front and back whitespace
$_=~s/(\bwhat\s*is\s*(the)?)//ig;# remove "what is the" (optional: the)
$_=~s/\b(the|for|of|is|entity|decode|decoded|code|character)\b//ig;# remove filler words
$_=~s/^\s+|\s+$//g;# remove front and back whitespace that existed in between that may show up after removing the filler words
$_=~s/\s*\?$//g;# remove ending question mark
returnunless((/^(&?#(?:[0-9]+(?!_))+;?)$/)||(/^(&(?:[a-zA-Z]+(?!_))+;?)$/)||(/^(&?#[xX](?:[0-9A-Fa-f]+(?!_))+;?)$/));# decimal (') || text with no underscores (¢) || hex (')
# "&" optional for all
# ";" optional except in text type
# "?" optional: question-like queries
# Standardize the query so it works well with library decoding functions
my$entity=$1;
$entity=~s/^&?/&/;# append '&' at the front
$entity=~s/;?$/;/;# append ';' at the back
# Attempt to decode, exit if unsuccessful
my$decoded=decode_entities($entity);# decode_entities() returns the input if unsuccesful
my$decimal=ord($decoded);
my$hex=sprintf("%04x",$decimal);
returnif(lc$entityeqlc$decoded);# safety net -- makes trying to decode something not real like "&enchantedbunny;" fail
# If invisible character, provide link instead of displaying it
my$info=charinfo($decimal);# charinfo() returns undef if input is not a "real" character
returnunless(defined$info);# another safety net
if($$info{name}eq'<control>'){
$decoded="Unicode control character (no visual representation)";
$entity="<a href='https://en.wikipedia.org/wiki/Unicode_control_characters'>Unicode control character</a> (no visual representation)";
}elsif(substr($$info{category},0,1)eq'C'){
$decoded="Special character (no visual representation)";
$entity="<a href='https://en.wikipedia.org/wiki/Special_characters'>Special character (no visual representation)";
}
# Make answer
return"Decoded HTML Entity: $decoded, Decimal: $decimal, Hexadecimal: $hex",