You need to put the variable noHREFas a static member variable of your class.
static Pattern noHREF = Pattern.compile("<a.+?>", Pattern.CASE_INSENSITIVE);
public static String getStringWithHREFsRemoved(String html) {
Matcher m = noHREF.matcher(html);
In the code that you wrote in your question, the noHREF variable means a local (temporary) variable whose scope is between static {and }.
source
share