javascript regex pattern with a variable string not working
<p>I am trying to create a function that will pass some parameters to a regex script:</p>

<pre><code>function classAttributes( classString, className ) {
    var data;
    var regex = new RegExp(className+"\[(.*?)\]");
    var matches = classString.match(regex);

    if ( matches ) {
        //matches[1] refers to options inside [] "required, email, ..."
            var spec = matches[1].split(/,\s*/);

            if ( spec.length &gt; 0 ) {
                data = spec;
            }
    }

    return data;
}
</code></pre>

<p>but for some reason it doesnt like the string variable that I pass it "new RegExp(className+"[(.*?)]");"
it doesnt throw an error but the validation doesnt work.</p>

<p>Edit:
I will take the information from the class stribute and pass it as classString</p>

<pre><code>&lt;div class="field-character-count test[asd, 123, hello]"&gt;&lt;/div&gt;
</code></pre>

<p>and the "className" will represent "test"</p>
