escapingvelocityapache-velocityvelocity-template-language

Removing brackets from velocity template (xml escaping)


I am new to velocity template. I am using velocity template to parse the data in xml format. Using below code to fetch userId: $esc.xml("$!userDetails.userId).replaceAll("&#[0-9a-fA-F]+;","")

Generated output: [ABC123] Excepted output: ABC123

Can someone please help me here. Also, I googled for apache velocity wiki but didn't find one. Also, it would be better if provide some wiki to fetch more information.

Thanks in advance!!


Solution

  • Escape [] characters which are regular expression keywords

    .replaceAll("&#\[0-9a-fA-F\]+;","")