gpt4 book ai didi

java - 如何在jSTL中使用正则表达式?

转载 作者:行者123 更新时间:2023-11-30 02:33:20 24 4
gpt4 key购买 nike

我在tld文件中定义了一个函数。它运行良好。但是如果我想从jsp传递一个参数,它显示错误。这是怎么回事?

 public static boolean matcheTelcom(CharSequence str) { 
public static String regTelcom="^(((153|133)\\d{8})|((1704|1707)\\d{7}))$";
return Pattern.compile(Constant.regTelcom).matcher(str).matches();
}

现在,我想将其更改为:

public static boolean matches(String pattern, CharSequence str) {
return Pattern.compile(pattern).matcher(str).matches();
}

在jsp中,我这样传递它:

 <c:if test="${mapping:matches('^(((153|133)\\d{8})|((1704|1707)\\d{7}))$',data.phone)}">  
This is a phone
</c:if>

错误显示:在带引号的字符串中,只有 []、['] 和 ["] 可以用 [] 转义。

最佳答案

您应该使用 \\\\d 而不是 \\d

The resean why you shoud use four \ because in java language \ have transferred meaning.you should use \\ means \,so does the same in regex expression.

关于java - 如何在jSTL中使用正则表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43751973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com