I've tried different ways to make the special character '-' work, but it doesn't seem to work when I try to test the regex within the code. The examples I tried were these
[^(a-zA-Z0-9\\\\@#$%!.'{}_-~`())]
The above one would not work as it searches for characters between '_' to '~'. Then I tried with
[^(a-zA-Z0-9\\\\@#$%!.'{}_~`()\\-)]
[^(a-zA-Z0-9-\\\\@#$%!.'{}_~`())]
[^(a-zA-Z0-9\\-\\\\@#$%!.'{}_~`())]
None of the above seem to be working if I give '-' in the string to search. The above expressions work when I try to test in regex tester online.
EXTERNAL_USER_INVALID_PATTERN = "[^(a-zA-Z0-9\\\\@#$%!.'{}_~`()\\-)]"
Pattern p = Pattern.compile(X.EXTERNAL_USER_INVALID_PATTERN);
if(p.matcher(objectName).find() || objectName.length()> X.EXTERNAL_USER_MAXLENGTH){
throw new BusinessException("The group name does not conform to specification");
}
It always throws the given exception. All the other combinations without '-' seems to be working.