<p>I have the following very simple Javascript-compatible regular expression:</p>

<pre><code>&lt;script type="text/javascript" id="(.+)" src="([^"]+)"&gt;
</code></pre>

<p>I am trying to match on script tags and gather both the ID and src attributes. I'd like to make the order of the attributes irrelevant, so that the following will still match:</p>

<pre><code>&lt;script id="..." type="text/javascript" src="..."&gt;
&lt;script src="..." id="..." type="text/javascript"&gt;
&lt;script id="..." src="..." type="text/javascript"&gt;
</code></pre>

<p>Is it possible to allow the attributes to appear in any order without compromising its ability to collect the matching ID and src?</p>

<p><em>edit</em> The string to match on is coming from innerHTML, making DOM traversal impossible. Also, I cannot use any third party libraries for this specific application.</p>

Try the following:
```
```
<script\s*\S*\s*(id="([^"]+)")?\s*\S*\s*(src="([^"]+)")\s*\S*\s*(id="([^"]+)")?[^>]*>
```
```
since you don't care about the type, just remove it because it makes things more complicated.  And then just brute force the rest by adding two optional ID's on either sice of the src.
Alternatively you can do
```
```
<script\s*(([^=]*)="([^"]*)")+\s*>
```
```
To get all the attributes and then pick out the ones you want in code.