Here&#x27;s a 1-1 port in JavaScript <a href="https:&#x2F;&#x2F;github.com&#x2F;benjamingr&#x2F;js-restructure" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;benjamingr&#x2F;js-restructure</a><p><pre><code>    function matcher(obj) { &quot;use strict&quot;;
      let props = Object.getOwnPropertyNames(obj);
      const re = new RegExp(props.reduce((p, c) =&gt; p + (c.startsWith(&quot;_&quot;) ? obj[c] : `(${obj[c]})`), &quot;&quot;));
      props = props.filter(x =&gt; !x.startsWith(&quot;_&quot;));
      return function(pattern) { 
      let o = {};
      const res = re.exec(pattern);
      for(let i = 0; i &lt; res.length; i++) o[props[i]] = res[i+1];
        return o;
      };
    }
</code></pre>
And example usage:<p>```js
    matcher({
       _    : &quot;^&quot;,
       user : &quot;\\w+&quot;,
       _2   : &quot;@&quot;,
       host : &quot;[^@]+&quot;,
       _3    : &quot;$&quot;
    })(&quot;user@ycombinator.com&quot;)
```