Q:

How to set a regex string with spring without it being escaped? 

I'm using spring for setting my regular expression
spring:
<property name="regularExpressionAsString" value="(?&lt;!\\.TMP)\\Z" />

code:
public void setRegularExpressionAsString(String regularEx) {
    this.regularExpression = Pattern.compile(regularEx);
}

This doesn't work properly and when I debug my setter I've seen that spring escapes the \ to \\ Is there any way to fix this? 

A:

While not answering your original question: Have you considered changing the setter argument to a java.util.regex. Pattern directly?  Spring has a PropertyEditor for that, so that you can have your Pattern injected directly:
application-context:
<property name="regularExpression" value="(?&lt;!\.TMP)\Z" />

bean:
public void setRegularExpression(Pattern regularExpression) {
    this.regularExpression = regularExpression;
}

A:

Have you considered setting the Regex String in a property file?  That way, you get the added bonus of being able to change the regex (should you need to) without a full recompile of your application. 
You could still set it up in a Spring XML configuration using a PropertyPlaceholderConfigurer.