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

Is there a MULTILINE support for hyperscan? #213

Open
apismensky opened this issue Dec 4, 2023 · 0 comments
Open

Is there a MULTILINE support for hyperscan? #213

apismensky opened this issue Dec 4, 2023 · 0 comments

Comments

@apismensky
Copy link

apismensky commented Dec 4, 2023

HS_FLAG_MULTILINE does not seem to have any impact in java API.

public class Validator {

    private static final EnumSet<ExpressionFlag> flags = EnumSet.of(ExpressionFlag.CASELESS, ExpressionFlag.PREFILTER, ExpressionFlag.MULTILINE);
    private static boolean isRegexValidHyperscan(String regex) {
        Expression expression = new Expression(regex, flags);
        Expression.ValidationResult result = expression.validate();
        if (result.getErrorMessage() != null) System.out.println(result.getErrorMessage());
        return result.isValid();
    }

    private static boolean isRegexValidJava(String regex) {
        try {
            Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
            return true;
        } catch (PatternSyntaxException e) {
            e.printStackTrace();
            return false;
        }
    }


    public static void main(String[] args) throws Exception {
        String regex = "\\d{13}^[A-Z]{1}";

        boolean regexValidHyperscan = isRegexValidHyperscan(regex);
        System.out.println(regex + " valid by hyperscan: " +  regexValidHyperscan);

        boolean regexValidJava = isRegexValidJava(regex);
        System.out.println(regex + " valid by java: " +  regexValidJava);
    }
}

produces

Embedded start anchors not supported.
\d{13}^[A-Z]{1} valid by hyperscan: false
\d{13}^[A-Z]{1} valid by java: true

@gliwka from what I read it should from the doc it should ve a valid regex, right?

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

1 participant