json-schema-validator-demo icon indicating copy to clipboard operation
json-schema-validator-demo copied to clipboard

Case insensitive regex not working

Open sdindiver opened this issue 3 years ago • 0 comments

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](https://user-images.githubusercontent.com/9547856/141121243-6b0c3a96-13eb-4fc9-87dd-f95452941d0f.png)

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](https://user-images.githubusercontent.com/9547856/141120399-5daf3ceb-cc7f-4c12-b2ef-04c3b0ff0060.png)

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); }




sdindiver avatar Nov 10 '21 13:11 sdindiver