Getting raw text from JTextPane

前端 未结 4 1693
粉色の甜心
粉色の甜心 2020-12-16 05:24

In my application, I use a JTextPane to display some log information. As I want to hightlight some specific lines in this text (for example the error messages),

4条回答
  •  长情又很酷
    2020-12-16 06:09

    (Is RegExp allowed? This isn't parsing, isn't it)

    Take the getText() result and use String.replaceAll() to filter all tags. Than a trim() to remove leading and trailing whitespaces. For the whitespaces between your first and you last 'blabla' I don't see a general solution. Maybe you can spilt the rest around CRLF and trim all Strings again.

    (I'm no regexp expert - maybe someone can provide the regexp and earn some reputation ;) )

    Edit

    .. I just assumed that you don't use < and > in your text - otherwise it.. say, it's a challenge.

提交回复
热议问题