Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Velocity Regex using JDK1.4.2 |
|
Author |
|
snoopygee
Joined: 11 Jun 2010 Posts: 2
|
Posted: Fri 11 Jun '10 10:59 Post subject: Velocity Regex using JDK1.4.2 |
|
|
Hi I am trying to split some text strings using a Velocity Template but seem to be running into an issue.
Given the following String:
Quote: | "Dave .P/did not g//o to the .G/market wh/en .he was supposed to" |
I am using the following code in my template:
Code: | #macro( splitAndPrintOnCarriageReturn $value $max )
#set ($strings = $value.split("\.[A-Z]/"))
#set ($start = true)
#foreach ($s in $strings)
#if($start == false)
<br>
#end
#set ($start = false )
#splitAndPrintString( $s $max )
#end
#end |
In this example I am trying to split the string on .P/ and .G/ However the string is not split at all, almost as if my regex is incorrectly formatted. I have read on some obscure site that perhaps because I am using this with a JRE1.4.2 application, the template cannot recognise regular expressions but I don't know whether this is true.
Any help here would be most appreciated.
Thanks |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Fri 11 Jun '10 14:27 Post subject: |
|
|
First, I have no idea what velocity is, not sure I even want to.
If you take your code and put a P where the [A-Z] is, does it make the first split in the sample and give you $strings[0] and $strings[1]?
If that works then obviously it does not accept [A-Z].
If not, does the trailing forward slash need to be escaped (a perl thing but never know)? |
|
Back to top |
|
snoopygee
Joined: 11 Jun 2010 Posts: 2
|
Posted: Fri 11 Jun '10 16:22 Post subject: |
|
|
Hi, thanks for your reply.
Quote: | If you take your code and put a P where the [A-Z] is, does it make the first split in the sample and give you $strings[0] and $strings[1]? |
No regular expression seems to work at all, that's why I was wondering whether it was related to the Java version, or indeed whether regex is handled in any version.
Thanks |
|
Back to top |
|
|
|
|
|
|