public class StrFilter { public static String filtrate(String str, char start, char end){
StringBuffer buffer = new StringBuffer();
int i = 0, leg = 0;
boolean isStart = false;
while(i != -1){
if (isStart){
isStart = false;
i = str.indexOf(end);
str = str.substring(i +1);
// System.out.println(i + " str=" + str);
}
else {
isStart = true;
i = str.indexOf(start);
if(i == -1){
leg = str.length();
}
else{
leg = i;
}
buffer.append(str.substring(0, leg).toCharArray());
// System.out.println(i + " buffer=" + buffer);
}
}
return buffer.toString();
}

public static String filtrate(String str, String start, String end){
StringBuffer buffer = new StringBuffer();
int i = 0, leg = 0;
boolean isStart = false;
while(i != -1){
if (isStart){
isStart = false;
i = str.indexOf(end);
if(i == -1){
leg = str.length();
}
else{
leg = i;
}
buffer.append(str.substring(start.length() - 1, leg).toCharArray());
}
else {
i = str.indexOf(start);
if(i > -1){
isStart = true;
}
str = str.substring(i + 1);
}
}
return buffer.toString();
}

public static ArrayList getNames(String str, String start, String end){
ArrayList names = new ArrayList();
String tmp = str;
int index;
while((index = tmp.lastIndexOf(start)) >=0){
names.add(filtrate(tmp, start, end));
tmp = tmp.substring(0, index);
}

return names;
}

public static void main(String[] args){
System.out.println(filtrate("<font color=#e10900>sdas</font>423123", '<', '>'));
System.out.println(filtrate("<table><tr><td>Hello: Good!</td><td>How are you: Fine!</td></tr></table>", "<td>How are you:", "</td>"));
System.out.println(filtrate(" [IMG]SJDKFJKASDKF[/IMG]SADF", "[IMG]", "[/IMG]"));
System.out.println(getNames("[IMG]ASJDKFJKASDKF[/IMG]SADF[IMG]SADFASDFASDFASDFSADF23[/IMG]", "[IMG]", "[/IMG]"));
}
}