logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



Velocity Regex using JDK1.4.2

 
Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner



View previous topic :: View next topic  
Author Message
snoopygee



Joined: 11 Jun 2010
Posts: 2

PostPosted: Fri 11 Jun '10 10:59    Post subject: Velocity Regex using JDK1.4.2 Reply with quote

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: 2123
Location: Sun Diego, USA

PostPosted: Fri 11 Jun '10 14:27    Post subject: Reply with quote

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

PostPosted: Fri 11 Jun '10 16:22    Post subject: Reply with quote

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


Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner
Page 1 of 1