程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> Freemaker WordStr函數的正則表達式應用

Freemaker WordStr函數的正則表達式應用

編輯:關於JAVA

Freemaker WordStr函數的正則表達式應用。本站提示廣大學習愛好者:(Freemaker WordStr函數的正則表達式應用)文章只能為提供參考,不一定能成為您想要的結果。以下是Freemaker WordStr函數的正則表達式應用正文


replace(param1,param2,param3)

param1 正則表達式;param2 將婚配的字符調換成指定字符;param3 形式

param3 參數以下

形式 i r m s c f replace 支撐 支撐 只和r 組合 只和r 組合 只和r 組合 支撐



形式說明:

i: Case insensitive: 疏忽年夜小寫

f: First only. That is, replace/find/etc. only the first occurrence of something.

r: The substring to find is a regular expression.尺度正則表達式(http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html )

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.在正則表達式中許可空格和正文。

典范以下:

<#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')} 

輸入成果:

foo bAr XYar
i: foo XYr XYar
if: foo XYr baar
r: foo XYAr XYr
ri: foo XYr XYr
rif: foo XYr baar 

更多典范:

原文:str = 2積分兌換30元優惠券

${str?replace('\\b\\d+積分','','r')}

輸入:兌換30元優惠券

ps:freemarker的replace功效

調換字符串 replace 

${s?replace(‘ba', ‘XY' )} 
${s?replace(‘ba', ‘XY' , ‘規矩參數')}

將s裡的一切的ba調換成xy 規矩參數包括: i r m s c f 詳細寄義以下: 

· i: 年夜小寫不辨別. 
· f: 只調換第一個湧現被調換字符串的字符串 
· r:  XY是正則表達式 

· 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. 

· s: Enables dotall mode for regular expressions (same as Perl singe-line mode). In dotall 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. 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved