1

[^\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);
2

2 Answers 2

1

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 \uas 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("\\","\\\\");
Sign up to request clarification or add additional context in comments.

2 Comments

it is not working...Actually I am using this Pattern to wrap up the invalid character present in the incoming xml file with CDATA. But this solution not working...
hmm, maybe it is because it is loading the literal string from the file? you could try replacing single slashes in your xml file for double backslashes. or try replacing it inside java. editing my answer accordingly.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.