0

How should I escape the following Java code, so I can use it in a Spring-EL expression?

Java:

.replaceAll("[\\p{Punct}&&[^\"|\\]|\\[|+|\\-|:|(|)|_|~|.|,|%|?]]", " ")

Spring-EL, which doesn't parse:

<int:transformer 
    input-channel="splitTitles" 
    output-channel="lowercasedTitles" 
    expression="payload.toLowerCase().replaceAll('[\\p{Punct}&&[^\"|\\]|\\[|+|\\-|:|(|)|_|~|.|,|%|?]]').trim()">
</int:transformer>
Rob
  • 4,927
  • 12
  • 49
  • 54
DeejUK
  • 12,891
  • 19
  • 89
  • 169

1 Answers1

0

You must escape special characters (i.e. & = &amp;, " = &quot;) when specifying attribute values in an XML-based file. Also, you didn't specify the second parameter to the replaceAll method call. Try this,

<int:transformer 
        input-channel="splitTitles" 
        output-channel="lowercasedTitles" 
        expression="payload.toLowerCase().replaceAll('[\\p{Punct}&amp;&amp;[^\&quot;|\\]|\\[|+|\\-|:|(|)|_|~|.|,|%|?]]', ' ').trim()">
    </int:transformer>
artbristol
  • 32,010
  • 5
  • 70
  • 103
jay c.
  • 1,521
  • 10
  • 9