Removing Asterisks and neighbors from a string
Regular expressions are the right tool for this sort of problem, and your suspicions that your code is not great, is about right.... there's the + operator in regular expressions which will do what you want much more concisely. + matches 1-or-more times.

Consider the simple expression:

String compact = raw.replaceAll(".?\\*+.?", "");


That replaces all something-stars-something patterns with nothing.

Note, this pattern will have the following results:

ab*cd     ad
ab***cd   ad
a**b      
ab****    a


etc.

The way the expression works is as follows:

Key features of the regex are:


\\*+ - * is normally a special character. We have to escape it with \\ to make it a normal *. The + is a 1-or-many match. What does this mean? It means that the expression \\*+ will match at least one * character, perhaps many of them in a row.
.? this is a non-greedy 0-or-1 match of any character. This requires some explaining. This will match at most 1 character, but, if the overall pattern will fail to match something, then the pattern can be tried again but matching nothing. What it means, is: "if possible, match 1 character - any character (including *)"


Putting them together, you get an expression that matches any character, if there is one, before an asterisk, as well as the asterisk, and any other asterisks that follow it, and finally any other character, if there is one.

See this in an ideone here: http://ideone.com/6yMSvx