问题
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