public static <T> void replaceSpans(final Spannable spannable, final Class<T> type, final Function<T, Object> replacementSpan)  {
        final T[] spans = spannable.getSpans(0, spannable.length(), type);
        for (final T span : spans) {
            final int start = spannable.getSpanStart(span);
            final int end = spannable.getSpanEnd(span);
            final int flags = spannable.getSpanFlags(span);
            spannable.removeSpan(span);
            final Object newSpan = replacementSpan == null ? null : replacementSpan.apply(span);
            if (newSpan != null) {
                spannable.setSpan(newSpan, start, end, flags);
            }
        }
    }
replaces searches and removes or replaces spans in a spannable
main/src/main/java/cgeo/geocaching/utils/html/HtmlUtils.java