Determine if a path is subdirectory of another in Node.js
<p>I am working on a <a href="https://github.com/jsdario/replyer" rel="noreferrer">MQTT handler</a> for which I want to emit an event for each parent directory where there is a event listener. For example:</p>

<p>If there are the following MQTT paths available, where there are subscriptors –there are event listeners for these paths–</p>

<ul>
<li><code>test</code></li>
<li><code>replyer/request</code></li>
<li><code>test/replyer/request</code></li>
</ul>

<p>And someone publishes on topic <code>test/replyer/request/@issuer</code>, there should be 2 events emmited: <code>test</code>, <code>test/replyer/request</code>.</p>

<p>Given than any path is possible and there is no list of available valid events, we must check only if a path is a parent of another. Can we do this with regex? If so, how would it look like? Is there a simpler/more efficient solution?</p>