anchor.diff:  ff(text)  -> "(.*)<(.*)\$".
   
   ff(Str,P,Groups) ->
  -  case re:run(Str,P,[{capture,Groups,list},dotall,caseless,ungreedy]) of
  +  case re:run(Str,P,[{capture,Groups,binary},dotall,caseless,ungreedy]) of
       {match,Ms} -> Ms;
       nomatch -> []
     end.
   
  -ws([X|Str]) when ?ws(X) -> ws(Str);
  +ws(?d(X,Str)) when ?ws(X) -> ws(Str);
   ws(Str) -> Str.
   
   dc(Str) -> string:to_lower(Str).
  
positive.code:   case ff(text,Str) of
      {{tag,""},EStr,{text,Txt}} -> 
        try [Token,{text,Txt}]++tokenize({{tag,""},EStr})
        catch _:_ -> tokenize({text,Txt++"&lt;"++EStr,Token})
        end;
      {{text,Str},"",eof} -> [Token,{eof,{text,Str}}]
    end;
  tokenize({TZ,Str,Token}) ->
    [{Token,{TZ,Str}}].
  
  tz(nil,"<"++Str)                        -> {{tag,""},ws(Str)};
  tz(nil,[_|Str])                         -> {nil,Str};
  
  tz({tag,""},"!--"++Str)                 -> {{comm,""},Str};
  tz({tag,""},"!"++Str)                   -> {{excl,""},ws(Str)};
  tz({tag,""},"?"++Str)                   -> {{que,""},ws(Str)};
  tz({tag,""},"/"++Str)                   -> {{end_tag,""},ws(Str)};
  tz({tag,Tag},Str) when ?endv(Str)       -> {{attr,"",{Tag,[]}},ws(Str)};
  tz({tag,Tag},[X|Str])when ?ok(X)        -> {{tag,Tag++[X]},Str};
  
  tz({excl,DT},">"++Str)                  -> {text,Str,{exclamation,dc(DT)}};
  tz({excl,DT},[X|Str])                   -> {{excl,DT++[X]},Str};
  
  tz({que,DT},"?>"++Str)                  -> {text,Str,{question,dc(DT)}};
  tz({que,DT},[X|Str])                    -> {{que,DT++[X]},Str};
  
  tz({comm,Comm},"-->"++Str)              -> {text,Str,{comment,Comm}};
  tz({comm,Comm},[X|Str])                 -> {{comm,Comm++[X]},Str};
  
  tz({etag,Tag,Attrs},"/>"++Str)          -> {text,Str,{sc,Tag,Attrs}};
  tz({etag,"script",Attrs},">"++Str)      -> {script,Str,{open,"script",Attrs}};
  tz({etag,"style",Attrs},">"++Str)       -> {style,Str,{open,"style",Attrs}};
  tz({etag,Tag,Attrs},">"++Str)           -> {text,Str,{open,Tag,Attrs}};
  
  tz({end_tag,Tag},Str) when ?endv(Str)   -> {{end_tag,Tag,'>'},ws(Str)};
  tz({end_tag,Tag,'>'},">"++Str)          -> {text,Str,{close,dc(Tag)}};
  tz({end_tag,Tag},[X|Str])               -> {{end_tag,Tag++[X]},Str};
  
  tz({attr,"",{Tag,As}},S)when ?endv(S)   -> {{etag,dc(Tag),As},S};
  tz({attr,A,{T,As}},S)when ?endv(S)      -> {{eatt,{dc(A),T,As}},ws(S)};
  tz({attr,A,TAs},[X|Str])when ?ok(X)     -> {{attr,A++[X],TAs},Str};
  
  tz({eatt,ATAs},"="++Str)                -> {{val,ATAs},ws(Str)};
  tz({eatt,{A,T,As}},S)                   -> {{attr,"",{T,As++[{A,""}]}},ws(S)};
  
  tz({val,ATAs},[X|Str])when ?sq(X)       -> {{sqval,"",ATAs},Str};%singlequoted
  tz({val,ATAs},[X|Str])when ?dq(X)       -> {{dqval,"",ATAs},Str};%doublequoted
  tz({val,ATAs},Str)                      -> {{uqval,"",ATAs},Str};%unquoted
  
  tz({sqval,V,{A,T,As}},[X|S])when ?sq(X) -> {{attr,"",{T,As++[{A,V}]}},ws(S)};
  tz({sqval,V,ATAs},[X|Str])              -> {{sqval,V++[X],ATAs},Str};
  
  tz({dqval,V,{A,T,As}},[X|S])when ?dq(X) -> {{attr,"",{T,As++[{A,V}]}},ws(S)};
  tz({dqval,V,ATAs},[X|Str])              -> {{dqval,V++[X],ATAs},Str};
  
  tz({uqval,V,{A,T,As}},S)when ?endv(S)   -> {{attr,"",{T,As++[{A,V}]}},ws(S)};
  tz({uqval,V,ATAs},[X|Str])              -> {{uqval,V++[X],ATAs},Str};
  
  tz(script,Str)                          -> ff(script,Str);
  tz(style,Str)                           -> ff(style,Str);
  tz(text,Str)                            -> ff(text,Str);
  
  tz(X,"")                                -> {X,"",eof}.
  
  ff(What,Str) ->
    case ff(Str,ff(What),[1,2]) of
  
negative.code: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% tokenizer
  
  %tz(<<>>,O)->lists:reverse(O);
  %   (<<X:8/integer,R/binary>>,O)->tz(R,[X|O])
  %end.
  
  
  -define(M(X),<<X,_/binary>>). % match
  -define(m(X,B),<<X,B/binary>>). % match
  -define(d(X,B),<<X:8/integer,B/binary>>). % decompose
  -define(D1(X,B),<<X:8/integer,_/binary>> = B). % decompose
  -define(D2(Y,B),<<Y:2/binary,_/binary>> = B). % decompose
  
  -define(ok(X),$a=<X,X=<$z;$A=<X,X=<$Z;$0=<X,X=<$9;X==$_;X==$-;X==$:).
  -define(ws(X),X==$\s;X==$\r;X==$\n;X==$\t).
  -define(dq(X),X==$").
  -define(sq(X),X==$').
  
  -define(ev(X), ?ws(X); X==$>; X== <<"/>">>; X==$=).
  
  tokenize(Str) when is_integer(hd(Str))-> tokenize(list_to_binary(Str));
  tokenize(Str) when is_binary(Str) -> tokenize(tz(nil,Str));
  
  tokenize({TZ,Str}) ->
    tokenize(tz(TZ,Str));
  