一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務器之家 - 編程語言 - JAVA教程 - Freemaker Replace函數(shù)的正則表達式運用

Freemaker Replace函數(shù)的正則表達式運用

2020-03-12 11:14jerrylsxu JAVA教程

這篇文章主要介紹了Freemaker Replace函數(shù)的正則表達式運用 的相關資料,需要的朋友可以參考下

replace(param1,param2,param3)

param1 正則表達式;param2 將匹配的字符替換成指定字符;param3 模式

param3 參數(shù)如下

 

模式 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.在正則表達式中允許空格和注釋。

范例如下:

?
1
2
3
4
5
6
7
<#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元優(yōu)惠券

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

輸出:兌換30元優(yōu)惠券

ps:freemarker的replace功能

替換字符串 replace 

?
1
2
${s?replace(‘ba', ‘XY' )}
${s?replace(‘ba', ‘XY' , ‘規(guī)則參數(shù)')}

將s里的所有的ba替換成xy 規(guī)則參數(shù)包含: i r m s c f 具體含義如下: 

· i: 大小寫不區(qū)分. 
· f: 只替換第一個出現(xiàn)被替換字符串的字符串 
· 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. 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产三级精品91三级在专区 | 欧美日韩一区二区三区久久 | 精品亚洲视频在线 | 国产福利专区精品视频 | 国产 国语对白 露脸正在播放 | 青青草国产免费国产是公开 | 青涩体验在线观看未删减 | 亚洲国产精品久久丫 | 99久久成人 | 五月天久久久 | 日韩精品免费看 | 二次元美女互摸隐私互扒 | 亚洲精品视频专区 | 男男羞羞视频网站国产 | 奇米社区 | 成人网18免费网 | 青青草成人影院 | 九九99香蕉在线视频免费 | 逼中极品| 舔比小说 | 青青国产成人久久激情911 | 久久久久影视 | 国产麻豆剧果冻传媒影视4934 | 久久精品亚洲精品国产欧美 | 欧美在线视频一区 | 天堂网在线.www天堂在线视频 | 国产第一综合另类色区奇米 | 精品国产区一区二区三区在线观看 | 蝴蝶传媒免费安装 | 暖暖的免费观看高清视频韩国 | 精品视频中文字幕 | 第一福利在线视频 | 极品ts赵恩静和直男激战啪啪 | 2018高清国产一道国产 | 德国高清freexxxx性 | 三极黄色 | 亚洲免费精品 | h视频免费高清在线观看 | 国产区久久| se01在线看片 | 精品综合久久久久久8888 |