regex matches
--------------------------
b(a|e|i)d bad bed bid
(?(test)true) // If positive lookahead test matches, match true regex
(?(test)true|false) // As above, otherwise match false regex
(?(capture)true) // If capture (name or number) contains text, match true regex
(?(capture)true|false) // As above, otherwise match false regex
(a|e|i) // = [aei]
// quoting style: single (') -> double (")
let text = "'I'm the cook,' he said, 'it's my job.'";
text.replace(/(^|\W)'|'(\W|$)/g, '$1"$2'));
// ╰─1──╯ ╰─2──╯
// ⭐️ Groups that are not matched will be replaced by nothing.
// → "I'm the cook," he said, "it's my job."