I’d like to create a RegEx Pattern statically, but I think I have the syntax wrong?
static {
Pattern noHREF = Pattern.compile("<a.+?>", Pattern.CASE_INSENSITIVE);
}
public static String getStringWithHREFsRemoved(String html) {
Matcher m = noHREF.matcher(html);
etc.....
You need to put the
noHREFvariable as a static member variable of your class.In the code you wrote in your question, the noHREF variable is imply a local (temporary) variable whose scope is between
static {and}.