如何将 fn:replace(string,pattern,replace) 与正则表达式一起使用?

问题描述 投票:0回答:1

我想使用替换来查找字符串中的

'[' and ']'
并将其替换为
blank spaces

我尝试过以下方法:

${fn:replace('[aus,zar]','(\[|\])','')}

但是我的系统抛出异常。

regex jsp replace find
1个回答
0
投票

请参阅,在

regular expressions (regex)
中,'['']' 作为字符类具有不同的含义。如果你想匹配它们,那么你需要通过添加反斜杠''来转义它们。 另外,'|'字符用于在正则表达式中指定
alternatives
,因此也需要对其进行转义。 请参考下面给出的代码

${fn:replace('[aus,zar]', '\\[|\\]', '')}

这可能会解决问题,如果不能,请评论该问题。

© www.soinside.com 2019 - 2024. All rights reserved.