[xwiki-devs] Re g exp not working in velocity code
Hi, I am having this weired problem. This is the velocity line #set($esctext = $text.replaceAll("\\s+","")) This should suppose to remove all the whitespaces in the text. If I execute same in java code it works fine. However if I use it in velocity code the same not working, we get $esctext same as $test. Now when I change the velocity code to #set($esctext = $text.replaceAll(" ","")) this is working all fine, and if the $text has single whitespaces, then this gets replaced. Thus bottom line is that replaceAll method is working fine and there is some issue with regexp only. Could someone please let me know if this is general issue with velocity or something to do with xwiki. Any reasons why its happening so? Thanks Sachin ----- http://www.assembla.com/wiki/show/sachin_mittal about me: -- View this message in context: http://www.nabble.com/Reg-exp-not-working-in-velocity-code-tp18112487p181124... Sent from the XWiki- Dev mailing list archive at Nabble.com.
See http://velocity.apache.org/engine/devel/user-guide.html#stringliterals Try #set($esctext = $text.replaceAll('\\s+',""))
Hi, I am having this weired problem. This is the velocity line #set($esctext = $text.replaceAll("\\s+",""))
This should suppose to remove all the whitespaces in the text. If I execute same in java code it works fine.
However if I use it in velocity code the same not working, we get $esctext same as $test.
Now when I change the velocity code to #set($esctext = $text.replaceAll(" ","")) this is working all fine, and if the $text has single whitespaces, then this gets replaced.
Thus bottom line is that replaceAll method is working fine and there is some issue with regexp only.
Could someone please let me know if this is general issue with velocity or something to do with xwiki. Any reasons why its happening so?
Thanks Sachin
----- http://www.assembla.com/wiki/show/sachin_mittal about me: -- View this message in context: http://www.nabble.com/Reg-exp-not-working-in-velocity-code-tp18112487p181124... Sent from the XWiki- Dev mailing list archive at Nabble.com.
_______________________________________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/mailman/listinfo/devs
Sachin Mittal wrote:
Hi, I am having this weired problem. This is the velocity line #set($esctext = $text.replaceAll("\\s+",""))
This should suppose to remove all the whitespaces in the text. If I execute same in java code it works fine.
However if I use it in velocity code the same not working, we get $esctext same as $test.
Now when I change the velocity code to #set($esctext = $text.replaceAll(" ","")) this is working all fine, and if the $text has single whitespaces, then this gets replaced.
Thus bottom line is that replaceAll method is working fine and there is some issue with regexp only.
Could someone please let me know if this is general issue with velocity or something to do with xwiki. Any reasons why its happening so?
The reason is \\, which is used by too many things. Try using a variable that contains \, for example: #set($bk = $escapetool.b) #set($esctext = $text.replaceAll("${bk}${bk}s+", "")) (if you are using an XWiki version that has the escape tool) -- Sergiu Dumitriu http://purl.org/net/sergiu/
Hi Sachin, On Jun 25, 2008, at 3:28 PM, Sachin Mittal wrote:
Hi, I am having this weired problem. This is the velocity line #set($esctext = $text.replaceAll("\\s+",""))
This should suppose to remove all the whitespaces in the text. If I execute same in java code it works fine.
However if I use it in velocity code the same not working, we get $esctext same as $test.
Now when I change the velocity code to #set($esctext = $text.replaceAll(" ","")) this is working all fine, and if the $text has single whitespaces, then this gets replaced.
Thus bottom line is that replaceAll method is working fine and there is some issue with regexp only.
Could someone please let me know if this is general issue with velocity or something to do with xwiki. Any reasons why its happening so?
I think that's because \ is the wiki syntax escape code so you need to write \\\\ instead of \\ -Vincent
participants (4)
-
Marius Dumitru Florea -
Sachin Mittal -
Sergiu Dumitriu -
Vincent Massol