<p>I am looking for a regex that will match a string that starts with one substring and does not end with a certain substring.</p>

<p>Example:</p>

<pre><code>// Updated to be correct, thanks @Apocalisp
^foo.*(?&lt;!bar)$
</code></pre>

<p>Should match anything that starts with "foo" and doesn't end with "bar".  I know about the [^...] syntax, but I can't find anything that will do that for a string instead of single characters.  </p>

<p>I am specifically trying to do this for Java's regex, but I've run into this before so answers for other regex engines would be great too.  </p>

<p>Thanks to @Kibbee for verifying that this works in C# as well.  </p>

I'm not familiar with Java regex but documentation for the
Pattern Class
would suggest you could use (?!X) for a non-capturing zero-width negative lookahead (it looks for something that is not X at that postision, without capturing it as a backreference). So you could do:
```
```
foo.*(?!bar) // not correct
```
```
Update
: Apocalisp's right, you want negative lookbehind. (you're checking that what the .* matches doesn't end with bar)