Skip to content

Case insensitive regex not working  #8

@sdindiver

Description

@sdindiver

I looked into library. I found below regex is giving false result. RhinoHelper is not supporting case insensitive regex support properly.

String regex = "/^[a-zA-Z0-9_.+-]+@(?:(?:[a-zA-Z0-9-]+.)?[a-zA-Z]+.)?(gmail.com)$/gi";
		boolean result = RhinoHelper.regMatch(regex,"[email protected]");


As RhinoHelper class is using RegExp function of javascript to validate and match RegEx. Java is passing regex as String in that javascript call.

image

but actual javascript accept regex without double quote. How would I achieve in java this behavior. Because with double quotes regex was giving correct result earlier untill and unless I tried case insensitiveness. If I pass regex without double quotes, It will work but not with double quotes
So if have to use case insensitiveness nature of this function, we have to pass "i" as second argument not like
/gi
image

Internal function used by RhinoHelper class to validate and match regex

function regexIsValid(re) {
    try {
        new RegExp(re);
        return true;
    } catch (e) {
        return false;
    }
}

function regMatch(re, input) {
    return new RegExp(re).test(input);
}

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