You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Allnoch Gerlinde <Al...@Verwaltung.uni-hohenheim.de> on 2005/06/07 13:25:35 UTC
ereg_replace
Hello,
i am looking for something like:
#set ($thema = ereg_replace('# ', '', $thema))
#set ($thema = ereg_replace('# ', '', $thema))
#set ($thema = ereg_replace('#', '', $thema))
How is it possible to do this ?
Regards,
Gerlinde Allnoch
Universität Hohenheim
Abteilung 1.2 EDV in der Verwaltung
Germany
Re: ereg_replace
Posted by Christoph Reck <ap...@recks.org>.
Allnoch Gerlinde wrote:
> Hello,
>
> i am looking for something like:
>
> #set ($thema = ereg_replace('# ', '', $thema))
>
> #set ($thema = ereg_replace('# ', '', $thema))
>
> #set ($thema = ereg_replace('#', '', $thema))
>
>
> How is it possible to do this ?
>
If you are running on a JDK 1.4 VM try:
#set( $thema = $thema.replaceAll('# ? ?', '') )
Other regular expression patterns might be more suitable, but
this does the same as your three lines above...
See more on String.replaceAll and Pattern in the API docs at:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#replaceAll(java.lang.String,%20java.lang.String)
http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
You could pack this into a veloci-macro,
#macro( ereg_replace $from $to $string )$string.replaceAll( $from, $to )#end
...
#set( $thema = "#ereg_replace('# ', '', $thema)" )
but IMHO the replaceAll is so straightforward packing it into
a macro is an overkill.
Cheers,
Christoph
>
>
> Regards,
>
> Gerlinde Allnoch
> Universität Hohenheim
> Abteilung 1.2 EDV in der Verwaltung
> Germany
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org