Regex to allow only # in the string and block the special characters
<p>I need to write a regex to allow the contents but block the special characters <code>'</code> and <code>--</code> in the string. I am working on a product which uses the regex to allow or block contents goofing around the product, I managed to find the below pattern:</p>

<pre><code>^('|--|#|\\x27|\\x23)$
</code></pre>

<p>Which is supposed to match <code>--</code>, <code>'</code> and <code>#</code> in the string, but when I tested this pattern in some online regex pattern matching. it was not highlighting the string when it contains <code>--</code>, <code>'</code> or <code>#</code>. </p>