【发布时间】:2015-04-23 21:15:32
【问题描述】:
我有这个正则表达式字符串:
^[a-zA-Z0-9\t\s\n\r!$()*,-./:;=?@`][{}_~|]+$
对于以下情况,该 RE 应该返回 true:
!$()*,-./:;=?@`][{}_~|
我正在使用 Apache 的 RE 并在运行 match 函数时出现错误。
我认为我的正则表达式缺少某些内容,可能是使用特殊字符进行处理。
问题是,我的表达有什么问题?
这是我的RE匹配函数:
public static String runRegularExpression(String string, String regularExpression, int parenthesis)
{
String result = null;
try
{
RE reCmd = new RE(regularExpression);
if (reCmd.match(string))
{
result = reCmd.getParen(parenthesis);
}
}
catch (Exception re)
{
}
return result;
}
【问题讨论】:
-
再次转义所有反斜杠。
-
我需要转义 RE 字符串吗?