Pattern p = Pattern.compile("<(a[^>]*)>");
Matcher m = p.matcher(str);
while (m.find())
{
int start = m.start();
int end = m.end();
chars[start] = '[';
chars[end-1] = ']';
}
String result = new String(chars);
System.out.println("before:" + str);
System.out.println(" after:" + result);