const regex = /\$(.*):(.*)\;/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\$(.*):(.*)\\;', 'g')
const str = `\$font-heading : var(--font-heading);
\$font-standard : var(--font-standard);
\$body-font-size : var(--body-font-size);
\$size-h1 : var(--size-h1);
\$size-h2 : var(--size-h2);
\$size-h3 : var(--size-h3);
\$size-h4 : var(--size-h4);
\$size-h5 : var(--size-h5);
\$size-h6 : var(--size-h6);
\$top-font-size: var(--top-font-size);
\$product-font-size: var(--product-font-size);
\$product-price-size: var(--product-price-size);
\$product-detail-size: var(--product-detail-size);
\$product-detail-title-size: var(--product-detail-title-size);
\$footer-size: var(--footer-size);
/* \$font-icon: 20px;
\$font-small-icon: 21px;
\$font-small: 14px;
\$font-medium: 17px;
\$font-bold: 300;
*/`;
const subst = `$1`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions