private static int endOfTagMatch(String string,int fromIndex,String tag){
  int pos=string.indexOf(tag,fromIndex);
  if (pos != -1) {
    while (pos < string.length() && Character.isWhitespace(string.charAt(pos)))     pos++;
    return pos + tag.length();
  }
  if (tag.contains(" ")) {
    tag=tag.replaceAll(" ","");
    pos=string.indexOf(tag);
    if (pos != -1) {
      while (pos < string.length() && Character.isWhitespace(string.charAt(pos)))       pos++;
      return pos + tag.length();
    }
  }
  return -1;
}

private static int endOfTagMatch ( String string , int fromIndex , String tag ) { int pos = string . indexOf ( tag , fromIndex ) ; if ( pos != - 1 ) { while ( pos < string . length ( ) && Character . isWhitespace ( string . charAt ( pos ) ) ) pos ++ ; return pos + tag . length ( ) ; } if ( tag . contains ( " " ) ) { tag = tag . replaceAll ( " " , "" ) ; pos = string . indexOf ( tag ) ; if ( pos != - 1 ) { while ( pos < string . length ( ) && Character . isWhitespace ( string . charAt ( pos ) ) ) pos ++ ; return pos + tag . length ( ) ; } } return - 1 ; }
matches tag to string ( allowing spaces inside tag to be missing in string )
