zedlander1000 zedlander1000 - 1 year ago 65
Java Question

How to remove character syntax from a string

Run down:
In my program, I format custom text by having character values leading the text it is going to format.

The syntax is '§#' or '§somecharacter'.
I have a string "Hello world!" but to make it underlined I do "§uHello World!" or to make it underlined and blue "§u§1Hello World!"

This is good for output but there are some times where I need to use "Hello World!" all by itself without the formatting syntax concatenated to the string.

The character '§' signifies format but the following character is unknown.

How would I remove all instances of '§' then the following character from the string?

Answer Source

This shall do the job for you, considering only alphabat or numeral follows §

String str = "§u§1Hello World!";
str.replaceAll("§[a-z0-9]", "");

Hope it helps.