Reputation: 177
[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF]
The above line showing illegal character range exception. Can anyone please help me.
if i use the above line in java code directly, it is not showing any error.
Pattern xmlInvalidChars = Pattern.compile("[^\\u0009\\u000A\\u000D\\u0020-\\uD7FF\\uE000-\\uFFFD\uD800\uDC00-\uDBFF\uDFFF]");
But if get the string from configuration xml file and use in the java code, it is showing error.
String chars = ConfigLoader.getInstance().getInvalidCharacters();
Pattern xmlInvalidChars = Pattern.compile(chars);
Upvotes: 1
Views: 3856
Reputation: 177
I used the below line in configuration xml file.
[^\\u0009\\u000A\\u000D\\u0020-\\uD7FF\\uE000-\\uFFFD\uD800\\uDC00-\\uDBFF\uDFFF]
that is i used the reverse case. i changed the single slash to double slash(\ to \) and double slash to single slash(\ to ). It is working now.
Upvotes: 0
Reputation: 468
I can't comment yet, so I'll post as an answer. inside your string you have loose backslashes \uD800\uDC00-\uDBFF\uDFFF
, therefore, it is treating \u
as and escape character, however it is not. just add double backslashes as the rest of your regex.
Edit: Before compiling the pattern, try to substitute single slashes with double slashes.
chars = chars.replace("\\","\\\\");
Upvotes: 1