JavaScript storing search matches in array <p>How to store the search matches from <code>id="post_body"</code> to array?</p> <blockquote> <pre><code>&lt;textarea name="post[body]" id="post_body"&gt; </code></pre> <p>--Lorem ipsum-- dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et --Dolore-- magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. --Duis aute-- irure dolor in reprehenderit in voluptate velit esse cillum --Dolore-- eu fugiat nulla pariatur</p> <p><code>&lt;/textarea&gt;</code></p> </blockquote> <p>The target are all words surrounded by '--'. In Ruby, I do that with:</p> <pre><code>matches = tex.scan(/--(.+?)--/).flatten matches = matches.uniq </code></pre> <p>In this case, the array would be: </p> <pre><code>matches = ["Lorem ipsum", "Dolore", "Duis aute"]; </code></pre> <p>NB: the word "Dolore" appears twice surrounded with <code>--</code>, but in the array it should be stored only once.</p>