JSFiddle - React, Tailwind, and code Playground
JavaScript
var str = "<name> BOBBY LEE </name>";
str = str.replace(/\s+/g, ' '); // Keep only one space character
str = str.replace(/>\s*/g, '>'); // Remove space after >
str = str.replace(/\s*</g, '<'); // Remove space before <
alert(str);