开发者

How do you escape regex strings in Freemarker

开发者 https://www.devze.com 2022-12-09 22:00 出处:网络
I am using the matches string builtin and need to run a regex pattern (Views:).*?(span>)(.*?)(<\\/div)

I am using the matches string builtin and need to run a regex pattern

(Views:).*?(span>)(.*?)(<\/div)

However, Freemarker freaks out because of the ">" character which is a special character in Freemarker. Any id开发者_运维技巧eas how to get round this?


Use \l for < and \g for >.

Taken from a FreeMarker documentation page which was second item in a Google search for "freemarker escape string".


Oh and be careful trying to parse HTML with regex - with uncontrolled markup it turns difficult very quickly.

0

精彩评论

暂无评论...
验证码 换一张
取 消