RegExp: Comments

I would love to have Perl compatible regular expression comments.

Comments begin with (?# and end at the next ).

Example

text.match(/true|false|undefined(?#indeterminate)/);

need to prove this feature necessity

Personally I would like to see a built in way of composing RegExps. So variable names and existing JS comment syntax can be used to describe the pattern.

Something like:

let version = 4;
let variant = /[89aAbB]/; // https://en.wikipedia.org/wiki/Universally_unique_identifier#Variants 
let hex = /[a-f0-9]/;
let firstHalf = RegExp.from`${hex}{8}-${hex}{4}-${version}${hex}{3}`;
let secondHalf = RegExp.from`${variant}${hex}{3}-${hex}{12}`;
let uuids = RegExp.from`${firstHalf}-${secondHalf}`;

assert(uuids.source === /[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}/.source);
Implementation
RegExp.from = function ({ raw }, ...vars) {
  function varToString(v) {
    let isRegex = RegExp(v) === v;
    return isRegex ? v.source : String(v);
  }

  return RegExp(
      raw
        .map((v, i) => (i === raw.length - 1 ? v : v + varToString(vars[i])))
        .join("")
    );
};