Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

表达式有\u等字符串编译报错 #602

Open
carterrr opened this issue Dec 27, 2023 · 1 comment
Open

表达式有\u等字符串编译报错 #602

carterrr opened this issue Dec 27, 2023 · 1 comment

Comments

@carterrr
Copy link

问题

我想注册一个函数 来实现自定义的正则匹配逻辑,函数是这样的:

 /**
     * 正则匹配
     *
     * @param str 字符串
     * @param reg 正则表达式
     * @param allMatches 是否全文匹配
     * @return 是否匹配
     */
    public static boolean matchPattern(String str, String reg, boolean allMatches) {
        if (StringUtils.isAnyEmpty(str, reg)) {
            return false;
        }
        Matcher matcher = Pattern.compile(reg).matcher(str);
        if (allMatches) {
            return matcher.matches();
        } else {
            return matcher.find();
        }

    }

当使用aviator表达式编译时 正则中的一些转义会抛出不支持的异常 比如这个表达式

return matchPattern('很好',  '[\u4e00-\u9fa5]{0,4}'); // 0-4个中文字符

其中\u会被解析器抛出无法识别异常

思路

请教下:如果移除源码中的 throw逻辑 ,可能会有哪些影响呢
com/googlecode/aviator/lexer/ExpressionLexer.java:394

image
@killme2008
Copy link
Owner

加个 \ 呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants