const regex = /(?:class="|\G(?!^))(?:(?!st)[^"])*\Kst/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:class="|\\G(?!^))(?:(?!st)[^"])*\\Kst', 'g')
const str = `foo st0 st1 st2 bar
class="st0 st1 st2", class="st3 st45", class="st678"
baz="st0 st1 st2"`;
const subst = `stx`;
// 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