anchor.diff:  'analyze-string'(Ctx,Input,Pattern0,Flags) ->
      Pattern = xqerl_types:string_value(Pattern0),
      Flags1 = xqerl_types:string_value(Flags),
  -   case xs_regex:compile(Pattern,Flags1) of
  +   case xs_regex:analyze(Pattern,Flags1) of
         {error, {invalid_flag, _}} ->
            ?dbg("invalid_flag",invalid_flag),
            ?err('FORX0001');
         {error, Err} ->
            ?dbg("Err",Err),
            ?err('FORX0002');
  -      {true,_} ->
  +      {true, _, _} ->
            ?dbg("true",true),
            ?err('FORX0003');
  -      {_,MP} ->
  +       {_, MP, Grps} ->
            Input1 = string_value(Input),
            Content = case re:run(Input1, MP, [global]) of
                         nomatch ->
  
positive.code:            if End == 0 ->
                   ?err('FORX0003'); % would match empty str
                true ->
                   {Pre++[Match],Start + End}
             end
       end,
     {Els,Pos} = lists:mapfoldl(Fun, 0, List),
     StrLen = string:length(String),
     Return = if Pos =/= StrLen andalso StrLen > 0 ->
                    Els ++ [analyze_string1([],string:slice(String,Pos))];
                 true ->
                    Els
              end,
     Return.
  
  %% all groups here are connected, could be sub-groups 
  get_groups(String,[{Start,End}],Cnt) ->
     [#xqElementNode{name = #qname{namespace = ?NS,
                                  prefix = ?PX,
                                  local_name = ?A("group")},
                    content = [#xqAttributeNode{name = 
                                               #qname{namespace = 'no-namespace', 
                                                      prefix = <<>>, 
                                                      local_name = ?A("nr")},
                                             string_value = ?str(integer_to_binary(Cnt))},
                            if End == 0 ->
                                  [];
                               true ->
                                  Slc = string:slice(String,Start,End),
                                  #xqTextNode{string_value = ?str(Slc)}
                            end
                           ]}];   
  get_groups(String,[{-1,0}|T],Cnt) ->
     get_groups(String,T,Cnt+1);   
  get_groups(String,[{Start,End},{NStart,NEnd}|Rest],Cnt) ->
     Pos1 = Start + End,
     if NStart < Pos1 orelse NEnd == 0;
        {Start,End} == {NStart,NEnd} -> % overlap/empty group
           %% XXX The second group may also be not contained in the first group,
           %% there is no way to tell...
           End1 = NStart - Start,
           Txt1 = #xqTextNode{string_value = ?str(string:slice(String,Start,End1))},
           Att1 = #xqAttributeNode{name = 
                                     #qname{namespace = 'no-namespace', 
                                            prefix = <<>>, 
                                            local_name = ?A("nr")}, 
                                   string_value = ?str(integer_to_binary(Cnt))},
           Grps = get_groups(String,[{NStart,NEnd}|Rest],Cnt + 1),
           [#xqElementNode{name = #qname{namespace = ?NS,
                                         prefix = ?PX,
                                         local_name = ?A("group")},
                           content = [Att1,
                                      Txt1,
                                      Grps]}];
        NStart > Pos1 -> % gap
           Length = NStart - Pos1,  
           Txt1 = #xqTextNode{string_value = ?str(string:slice(String,Start,End))},
           Txt2 = #xqTextNode{string_value = ?str(string:slice(String,Pos1,Length))},
           Att1 = #xqAttributeNode{name = #qname{namespace = 'no-namespace', 
                                                 prefix = <<>>, 
                                                 local_name = ?A("nr")}, 
                                   string_value = ?str(integer_to_binary(Cnt))},
           Grps1 = get_groups(String,[{NStart,NEnd}|Rest],Cnt + 1),
           [#xqElementNode{name = #qname{namespace = ?NS,
                                        prefix = ?PX,
                                        local_name = ?A("group")},
                          content = [Att1,Txt1]},
            Txt2|Grps1];
        true -> % no overlap
           Txt1 = #xqTextNode{string_value = ?str(string:slice(String,Start,End))},
           Att1 = #xqAttributeNode{name = #qname{namespace = 'no-namespace', 
                                                 prefix = <<>>, 
                                                 local_name = ?A("nr")}, 
                                   string_value = ?str(integer_to_binary(Cnt))},
           Grps2 = get_groups(String,[{NStart,NEnd}|Rest],Cnt + 1),
           [#xqElementNode{name = #qname{namespace = ?NS,
                                        prefix = ?PX,
                                        local_name = ?A("group")},
                          content = [Att1,Txt1]}|Grps2]
    end.
  
  %% Makes a dynamic call on a function with an argument list supplied 
  %% in the form of an array. 
  
negative.code:                    end,
           Expr = if Input1 == <<>> -> [];
                     true ->
                        analyze_string1(Content, Input1, Grps)
                  end,
           Frag = #xqElementNode{name = #qname{namespace = ?NS,
                                               prefix = ?PX,
  