Match A or B
const aOrB = /\b(a|b)\b/g;
const fn = '(b > .5) ? (max(a, 2. * (b - .5))) : (min(a, 2. * b))'
const r = fn.replace(aOrB, '$1.r');
const g = fn.replace(aOrB, '$1.g');
const b = fn.replace(aOrB, '$1.b');
console.log(r);
console.log(g);
console.log(b);
Match an a
or b
, but not when it’s part of another word.
Found myself needing this for auto-generating some shaders recently.