Regex not working in Velocity Template

馋奶兔 提交于 2019-12-23 09:27:17

问题


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?


回答1:


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, " "))` 


来源:https://stackoverflow.com/questions/19016794/regex-not-working-in-velocity-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!