问题描述:

How to convert this code into java code

$response = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $response);

I try this

String jsonStr = "Some Json string";

jsonStr.replaceAll("/[\x00-\x1F\x80-\xFF]/", "");

But it show an error

Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )

网友答案:

You have to escape the backslashes with another backslash like this:

jsonStr.replaceAll("[\\x00-\\x1F\\x80-\\xFF]", "");

Backslashes in strings introduce special characters in Java.

相关阅读:
Top