format: string to hyphen words separated; --> format-string-to-hyphen-words-separated
format: string to hyphen words separated; --> format-string-to-hyphen-words-separated
by Yury
HTML
<p>
format: string to hyphen words separated; --> format-string-to-hyphen-words-separated
</p>
CSS
* {
background: #1e1e1e;
font-family: sans-serif;
color: #c0c0c0;
text-align: center;
}
JavaScript
const toHyphenWords = str => {
return str.replace(/[^PAN-]-/g, '')
.replace(/(,|\.|:|;)/g, '')
// return str.replace(/((^PAN-))|(\,|\.|:|;|-)/g, '')
.replace(/\s+(\w)/g, (match, p1, p2, offset) => {
return `-${match.trim()}`;
})
// .replace(/,|\.|:|;/g, '')
.replace(/[^PAN][a-zA-z]+/g, (match, p1, p2, offset) => {
return match.toLowerCase()
});
};
var formatted = toHyphenWords('PAN-6406: POS: Redeem BD points and rewards in place;');
var formatted = toHyphenWords('PAN-4217 - Image editor - Large images choppy animation');
var formatted = toHyphenWords('Looker Analytics frame prototype');
var formatted = toHyphenWords('PAN-8009: POS: total due, credit value formatting request');
console.log('formatted: ', formatted);
// formatted: PAN-6406-pos-redeem-bd-points-and-rewards-in-place