)
}
}
)
(
}
{
)
)
(
)
(
(
{
}
)
(
)
}
)
)
{
(
(
)
)
}
)
(
}

Match A or B

  1. const aOrB = /\b(a|b)\b/g;
  2.  
  3. const fn = '(b > .5) ? (max(a, 2. * (b - .5))) : (min(a, 2. * b))'
  4.  
  5. const r = fn.replace(aOrB, '$1.r');
  6. const g = fn.replace(aOrB, '$1.g');
  7. const b = fn.replace(aOrB, '$1.b');
  8.  
  9. console.log(r);
  10. console.log(g);
  11. 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.

snippet.zone ~ 2021-22 /// {s/z}