Attribute Starts With Selector [name^=value]
<p>I need to match some input fields by name. The name consist of a base name plus squares brackets, so the PHP interpreter converts them to array. According to the jQuery API, I could use the following selector:</p>

<pre><code>":input[name^=foo\\[]"
</code></pre>

<p>(It's okay to ignore the closing bracket.) However, it won't match any of the elements. Other variations trigger an exception that I can't manage to catch properly. What am I missing?</p>

<pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;&lt;title&gt;&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;&lt;!--
jQuery(function($){
    // Expected result: 4
    var found = [];

    // 5
    found.push($(":input[name^=foo]").size());

    // uncaught exception: Syntax error, unrecognized expression: ]
    //found.push($(":input[name^=foo[]").size());

    // undefined
    try{
        found.push($(":input[name^=foo[]").size());
    }catch(e){
        found.push("Exception: " + e.description);
    }

    // uncaught exception: Syntax error, unrecognized expression: ]
    //found.push($(":input[name^=foo\[]").size());

    // undefined
    try{
        found.push($(":input[name^=foo\[]").size());
    }catch(e){
        found.push("Exception: " + e.description);
    }

    // 0
    found.push($(":input[name^=foo\\[]").size());

    alert("Items found:\n" + found.join("\n"));
});
//--&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;p&gt;&lt;input type="text" name="foo[-1]" value="A"&gt;&lt;/p&gt;
&lt;p&gt;&lt;input type="text" name="foo[0]" value="B"&gt;&lt;/p&gt;
&lt;p&gt;&lt;input type="text" name="foo[1]" value="D"&gt;&lt;/p&gt;
&lt;p&gt;&lt;input type="text" name="foo[]" value="D"&gt;&lt;/p&gt;
&lt;p&gt;&lt;input type="text" name="foobar" value="Z"&gt;&lt;/p&gt;


&lt;/body&gt;
&lt;/html&gt;
</code></pre>
