Forum Discussion
- OlivierSLithium Alumni (Retired)
dhiraj_gophane or maybe try to use Regex ?
From the freemarker documentation:
Common flags
Many string built-ins accept an optional string parameter, the so called ``flags''. In this string, each letter influences a certain aspect of the behavior of the built-in. For example, letter i means that the built-in should not differentiate the lower and upper-case variation of the same letter. The order of the letters in the flags string is not significant.
This is the complete list of letters (flags):
-
i: Case insensitive: do not differentiate the lower and upper-case variation of the same letter.
-
f: First only. That is, replace/find/etc. only the first occurrence of something.
-
r: The substring to find is a regular expression. FreeMarker uses the variation of regular expressions described at http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html (note that the presence of some pattern features depends on the Java version used).
-
m: Multi-line mode for regular expressions. In multi-line mode the expressions ^ and $match just after or just before, respectively, a line terminator or the end of the string. By default these expressions only match at the beginning and the end of the entire string. Note that ^ and $ doesn't match the line-break character itself.
-
s: Enables dot-all mode for regular expressions (same as Perl singe-line mode). In dot-all mode, the expression . matches any character, including a line terminator. By default this expression does not match line terminators.
-
c: Permits whitespace and comments in regular expressions.
Example:
<#assign s = 'foo bAr baar'> ${s?replace('ba', 'XY')} i: ${s?replace('ba', 'XY', 'i')} if: ${s?replace('ba', 'XY', 'if')} r: ${s?replace('ba*', 'XY', 'r')} ri: ${s?replace('ba*', 'XY', 'ri')} rif: ${s?replace('ba*', 'XY', 'rif')}
This outputs this:
foo bAr XYar i: foo XYr XYar if: foo XYr baar r: foo XYAr XYr ri: foo XYr XYr rif: foo XYr baar
-
Related Content
- 2 years ago
- 4 years ago
- 13 years agoInactive User