Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex not working in Velocity Template

I tried this in Test.java

String regex = "<\\s*br\\s*/*\\s*>";

String test1 = "< br/ >";

System.out.println(test.replaceAll(regex, " "));`

But when I try the same thing in a velocity template `

#set($brRegex = "<\\s*br\\s*/*\\s*>")
#set($imageDescription = $imageDescription.replaceAll($brRegex, " "))` 

And:

#set($imageDescription = $imageDescription.replaceAll("<\\s*br\\s*/*\\s*>", " "))`

Both don't work. Am I missing something?

like image 809
Vinodh Mahendrakumar Avatar asked Sep 25 '13 23:09

Vinodh Mahendrakumar


1 Answers

Omit the extra backslashes. No need to escape them. See Velocity Template - regular expressions

#set($brRegex = "<\s*br\s*/*\s*>")
#set($imageDescription = $imageDescription.replaceAll($brRegex, " "))` 
like image 55
joescii Avatar answered Oct 31 '22 18:10

joescii