Skip to content

Is there a MULTILINE support for hyperscan?  #213

@apismensky

Description

@apismensky

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions