How to remove string "\u001b[1m" in java
After I receive a content resp开发者_运维知识库onse of the server, and print the content to console and I realize existing of the string "\u001b[1m", and I think it's the reason I can't parse the conte tresponse as a JSON object.
And I want to remove the string, any solution?
That looks like an ANSI video escape sequence to turn bold mode on. Are you sure that the server is sending back a JSON object?
Make sure you know what's actually in the string -- try examining (and maybe printing) it character by character using someString.charAt()
.
And, String newString = someString.replaceAll(oldexp);
is one of many ways you might try to "fix" it, if it turns out that's needed.
That's an escape sequence, and I think it's used to turn on formatting in some things like the Terminal. Is that really supposed to be JSON? What's the rest of the text? Does that escape sequence come as plain text or as one character?
During the development of an SSH program that also utilizes command line mysql commands, I created the following regex that I strip these sequences with:
\u001b[\[\(]([0-9];[0-9]|\?[0-9]+)?[Bmh]
It covers the ranges that I have run into issues with
sed -E 's/\\u001b\[[0-9][0-9]?m//g'
精彩评论