anchor.diff:    end else if (NodeLeft^.NodeType=ntCHAR) and (NodeRight^.NodeType=ntCHAR) then begin
      result:=NewNode(ntCHAR,nil,nil,nil,0);
      result^.CharClass:=NodeLeft^.CharClass+NodeRight^.CharClass;
  -// result:=ConvertUTF8CharClassNode(NewNode(ntCHAR,nil,nil,nil,RegExp.AddCharClass(c)));
     end else begin
      result:=NewNode(ntALT,NodeLeft,NodeRight,nil,0);
     end;
  
positive.code:   end;
   end;
   function ParseDisjunction:PFLRENode; forward;
   function GetCharClass(const CurrentChar:ansichar;out IsSingle:boolean;out SingleChar:ansichar):TFLRECharClass;
   begin
    case CurrentChar of
     '0':begin
      result:=[#0];
      IsSingle:=true;
      SingleChar:=#0;
     end;
     't':begin
      result:=[#9];
      IsSingle:=true;
      SingleChar:=#9;
     end;
     'n':begin
      result:=[#10];
      IsSingle:=true;
      SingleChar:=#10;
     end;
     'v':begin
      result:=[#11];
      IsSingle:=true;
      SingleChar:=#11;
     end;
     'f':begin
      result:=[#12];
      IsSingle:=true;
      SingleChar:=#12;
     end;
     'r':begin
      result:=[#13];
      IsSingle:=true;
      SingleChar:=#13;
     end;
     'a':begin
      result:=['a'..'z','A'..'Z'];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'A':begin
      result:=AllCharClass-['a'..'z','A'..'Z'];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'w':begin
      result:=['a'..'z','A'..'Z','0'..'9','_'];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'W':begin
      result:=AllCharClass-['a'..'z','A'..'Z','0'..'9','_'];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     's':begin
      result:=[#9,#10,#13,#32];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'S':begin
      result:=AllCharClass-[#9,#10,#13,#32];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'd':begin
      result:=['0'..'9'];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'D':begin
      result:=AllCharClass-['0'..'9'];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'h':begin
      result:=['0'..'9','a'..'f','A'..'F'];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'H':begin
      result:=AllCharClass-['0'..'9','a'..'f','A'..'F'];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'c':begin
      result:=[#0..#31,#127];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'C':begin
      result:=AllCharClass-[#0..#31,#127];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'p':begin
      result:=['!','"','#','%','&','''','(',')',';','<','=','>','?','[','\',']','*','+',',','-','.','/',':','^','_','{','|','}','~'];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'P':begin
      result:=AllCharClass-['!','"','#','%','&','''','(',')',';','<','=','>','?','[','\',']','*','+',',','-','.','/',':','^','_','{','|','}','~'];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'l':begin
      result:=['a'..'z'];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'L':begin
      result:=AllCharClass-['a'..'z'];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'u':begin
      result:=['A'..'Z'];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     'U':begin
      result:=AllCharClass-['A'..'Z'];
      IsSingle:=false;
      SingleChar:=#0;
     end;
     else begin
      result:=[CurrentChar];
      IsSingle:=true;
      SingleChar:=CurrentChar;
     end;
    end;
   end;
   function GetCharClassPerName(const Name:ansistring):TFLRECharClass;
   begin
    if Name='alnum' then begin
     result:=['a'..'z','A'..'Z','0'..'9'];
    end else if Name='alpha' then begin
     result:=['a'..'z','A'..'Z'];
    end else if Name='ascii' then begin
     result:=[#$00..#$7f];
    end else if Name='blank' then begin
     result:=[#9,#32];
    end else if Name='cntrl' then begin
     result:=[#$00..#$1f,#$7f];
    end else if Name='digits' then begin
     result:=['0'..'9'];
    end else if Name='graph' then begin
     result:=[#$21..#$7e];
    end else if Name='lower' then begin
     result:=['a'..'z'];
    end else if Name='print' then begin
     result:=[#$20..#$7e];
    end else if Name='punct' then begin
     result:=['!','"','#','$','%','&','''','(',')','*','+',
                         ',','\','-','.','/',':',';','<','=','>','?',
                         '@','[','\',']','^','_','`','{','|','}','~'];
    end else if Name='space' then begin
     result:=[#9,#10..#13,#32];
    end else if Name='upper' then begin
     result:=['A'..'Z'];
    end else if Name='word' then begin
     result:=['a'..'z','A'..'Z','0'..'9','_'];
    end else if Name='xdigit' then begin
     result:=['a'..'f','A'..'F','0'..'9'];
    end else begin
     result:=[];
     raise EFLRE.Create('Syntax error');
    end;
   end;
  
negative.code:    end;
    end;
   end;
   function NewUnicodeChar(UnicodeChar:longword):PFLRENode;
   var Index:longint;
       TemporaryString:ansistring;
       TemporaryNode:PFLRENode;
   begin
    result:=nil;
    TemporaryString:=UTF32CharToUTF8(UnicodeChar);
    try
     for Index:=1 to length(TemporaryString) do begin
      TemporaryNode:=NewNode(ntCHAR,nil,nil,nil,0);
      TemporaryNode^.CharClass:=[TemporaryString[Index]];
      if assigned(result) then begin
       result:=Concat(result,TemporaryNode);
      end else begin
       result:=TemporaryNode;
      end;
     end;
    finally
     TemporaryString:='';
    end;
   end;
   function NewCharEx(UnicodeChar:longword):PFLRENode;
   begin           
    if (rfUTF8 in Flags) and (UnicodeChar>=$80) then begin
     result:=NewUnicodeChar(UnicodeChar);
    end else if UnicodeChar<=$ff then begin
     result:=NewNode(ntCHAR,nil,nil,nil,0);
     result^.CharClass:=[ansichar(byte(UnicodeChar))];
    end else begin
     raise EFLRE.Create('Syntax error');
    end;
   end;
   function NewChar(UnicodeChar:longword):PFLRENode;
   var LowerCaseUnicodeChar,UpperCaseUnicodeChar:longword;
   begin
    LowerCaseUnicodeChar:=UnicodeToLower(UnicodeChar);
    UpperCaseUnicodeChar:=UnicodeToUpper(UnicodeChar);
    if (rfCASEINSENSITIVE in Flags) and (LowerCaseUnicodeChar<>UpperCaseUnicodeChar) then begin
     if (rfUTF8 in Flags) and ((LowerCaseUnicodeChar>=$80) or (UpperCaseUnicodeChar>=$80)) then begin
      result:=NewAlt(NewCharEx(LowerCaseUnicodeChar),NewCharEx(UpperCaseUnicodeChar));
     end else begin
      result:=NewNode(ntCHAR,nil,nil,nil,0);
      result^.CharClass:=[ansichar(byte(LowerCaseUnicodeChar)),ansichar(byte(UpperCaseUnicodeChar))];
     end;
    end else begin
     if (rfUTF8 in Flags) and (UnicodeChar>=$80) then begin
      result:=NewCharEx(UnicodeChar);
     end else begin
      result:=NewNode(ntCHAR,nil,nil,nil,0);
      result^.CharClass:=[ansichar(byte(UnicodeChar))];
     end;
    end;
   end;
   function CompileUTF8Range(Lo,Hi:longword):PFLRENode;
   type TString6Chars=string[6];
   const Seq0010ffff:array[0..6,0..4,0..1] of longint=((($00,$7f),(-1,-1),(-1,-1),(-1,-1),(-1,-1)),        // 00-7F
                                                       (($c2,$df),($80,$bf),(-1,-1),(-1,-1),(-1,-1)),      // C2-DF 80-BF
                                                       (($e0,$e0),($a0,$bf),($80,$bf),(-1,-1),(-1,-1)),    // E0-E0 A0-BF 80-BF
                                                       (($e1,$ef),($80,$bf),($80,$bf),(-1,-1),(-1,-1)),    // E1-EF 80-BF 80-BF
                                                       (($f0,$f0),($80,$bf),($80,$bf),($80,$bf),(-1,-1)),  // F0-F0 90-BF 80-BF 80-BF
                                                       (($f1,$f3),($80,$bf),($80,$bf),($80,$bf),(-1,-1)),  // F1-F3 80-BF 80-BF 80-BF
                                                       (($f4,$f4),($80,$bf),($80,$bf),($80,$bf),(-1,-1))); // F4-F4 80-8F 80-BF 80-BF
         HexChars:array[$0..$f] of ansichar='0123456789ABCDEF';
   var OutputNode,NodeChain:PFLRENode;
    procedure Add(const NewNode:PFLRENode);
    begin
     if assigned(NewNode) then begin
      if assigned(NodeChain) then begin
       NodeChain:=Concat(OutputNode,NewNode);
      end else begin
       NodeChain:=NewNode;
      end;
     end;
    end;
    procedure AddSuffix;
    begin
     if assigned(NodeChain) then begin
      if assigned(OutputNode) then begin
       OutputNode:=NewAlt(OutputNode,NodeChain);
      end else begin
       OutputNode:=NodeChain;
      end;
      NodeChain:=nil;
     end;
    end;
    function ToString(CharValue:longword):TString6Chars;
    begin
     case CharValue of
      $00000000..$0000007f:begin
       SetLength(result,1);
       result[1]:=ansichar(byte(CharValue));
      end;
      $00000080..$000007ff:begin
       SetLength(result,2);
       result[1]:=ansichar(byte($c0 or ((CharValue shr 6) and $1f)));
       result[2]:=ansichar(byte($80 or (CharValue and $3f)));
      end;
   // {$ifdef PLREStrictUTF8}$00000800..$0000d7ff,$0000e000..$0000ffff{$else}$00000800..$0000ffff{$endif}:begin
      $00000800..$0000ffff:begin
       SetLength(result,3);
       result[1]:=ansichar(byte($e0 or ((CharValue shr 12) and $0f)));
       result[2]:=ansichar(byte($80 or ((CharValue shr 6) and $3f)));
       result[3]:=ansichar(byte($80 or (CharValue and $3f)));
      end;
      $00010000..$0010ffff:begin
       SetLength(result,4);
       result[1]:=ansichar(byte($f0 or ((CharValue shr 18) and $07)));
       result[2]:=ansichar(byte($80 or ((CharValue shr 12) and $3f)));
       result[3]:=ansichar(byte($80 or ((CharValue shr 6) and $3f)));
       result[4]:=ansichar(byte($80 or (CharValue and $3f)));
      end;
      $00200000..$03ffffff:begin
       SetLength(result,5);
       result[1]:=ansichar(byte($f8 or ((CharValue shr 24) and $03)));
       result[2]:=ansichar(byte($80 or ((CharValue shr 18) and $3f)));
       result[3]:=ansichar(byte($80 or ((CharValue shr 12) and $3f)));
       result[4]:=ansichar(byte($80 or ((CharValue shr 6) and $3f)));
       result[5]:=ansichar(byte($80 or (CharValue and $3f)));
      end;
      $04000000..$7fffffff:begin
       SetLength(result,6);
       result[1]:=ansichar(byte($fc or ((CharValue shr 30) and $01)));
       result[2]:=ansichar(byte($80 or ((CharValue shr 24) and $3f)));
       result[3]:=ansichar(byte($80 or ((CharValue shr 18) and $3f)));
       result[4]:=ansichar(byte($80 or ((CharValue shr 12) and $3f)));
       result[5]:=ansichar(byte($80 or ((CharValue shr 6) and $3f)));
       result[6]:=ansichar(byte($80 or (CharValue and $3f)));
      end;
      else begin
       SetLength(result,3);
       result[1]:=#$ef;
       result[2]:=#$bf;
       result[3]:=#$bd;
      end;
     end;
    end;
    procedure AddRange(const Lo,Hi:byte);
    var Node:PFLRENode;
    begin
     Node:=NewNode(ntCHAR,nil,nil,nil,0);
     Node^.CharClass:=[ansichar(byte(Lo))..ansichar(byte(Hi))];
     Add(Node);
    end;
    procedure ProcessRange(Lo,Hi:longword);
    var i,m:longword;
        StrLo,StrHi:TString6Chars;
        CurrentNode:PFLRENode;
    begin
     if Hi>$0010ffff then begin
      Hi:=$0010ffff;
     end;
     if Lo<=Hi then begin
      if (Lo=$00000000) and (Hi=$0010ffff) then begin
       for m:=low(Seq0010ffff) to high(Seq0010ffff) do begin
        for i:=low(Seq0010ffff[m]) to high(Seq0010ffff[m]) do begin
         if Seq0010ffff[m,i,0]<0 then begin
          break;
         end;
         AddRange(byte(Seq0010ffff[m,i,0]),byte(Seq0010ffff[m,i,1]));
        end;
        AddSuffix;
       end;
      end else if (Lo=$00000080) and (Hi=$0010ffff) then begin
       for m:=1 to high(Seq0010ffff) do begin
        for i:=low(Seq0010ffff[m]) to high(Seq0010ffff[m]) do begin
         if Seq0010ffff[m,i,0]<0 then begin
          break;
         end;
         AddRange(byte(Seq0010ffff[m,i,0]),byte(Seq0010ffff[m,i,1]));
        end;
        AddSuffix;
       end;
      end else begin
       for i:=1 to 3 do begin
        if i=1 then begin
         m:=7;
        end else begin
         m:=(7-i)+(6*(i-1));
        end;
        m:=(1 shl m)-1;
        if (Lo<=m) and (m<Hi) then begin
         ProcessRange(Lo,m);
         ProcessRange(m+1,Hi);
         exit;
        end;
       end;
       if Hi<128 then begin
        AddRange(Lo,Hi);
        AddSuffix;
       end else begin
        for i:=1 to 3 do begin
         m:=(1 shl (6*i))-1;
         if (Lo and not m)<>(Hi and not m) then begin
          if (Lo and m)<>0 then begin
           ProcessRange(Lo,Lo or m);
           ProcessRange((Lo or m)+1,Hi);
           exit;
          end else if (Hi and m)<>m then begin
           ProcessRange(Lo,(Hi and not m)-1);
           ProcessRange(Hi and not m,Hi);
           exit;
          end;
         end;
        end;
        StrLo:=ToString(Lo);
        StrHi:=ToString(Hi);
        if length(StrLo)=length(StrHi) then begin
         for i:=1 to length(StrLo) do begin
          AddRange(byte(StrLo[i]),byte(StrHi[i]));
         end;
         AddSuffix;
        end;
       end;
      end;
     end;
    end;
   begin
    OutputNode:=nil;
    NodeChain:=nil;
    ProcessRange(Lo,Hi);
    result:=OutputNode;
   end;
   function NewUnicodeCharClass(UnicodeCharClass:TFLREUnicodeCharClass):PFLRENode;
   var Range:TFLREUnicodeCharClassRange;
       Node:PFLRENode;
   begin
    UnicodeCharClass.Optimize;
    if UnicodeCharClass.IsSingle then begin
     result:=NewChar(UnicodeCharClass.First.Lo);
    end else begin
     if (rfUTF8 in Flags) and assigned(UnicodeCharClass.Last) and (UnicodeCharClass.Last.Hi>=128) then begin
      result:=nil;
      Range:=UnicodeCharClass.First;
      while assigned(Range) do begin
       if (Range.Lo<=$10ffff) and (Range.Lo=Range.Hi) then begin
        Node:=NewCharEx(Range.Lo);
       end else begin
        Node:=CompileUTF8Range(Range.Lo,Range.Hi);
       end;
       if assigned(result) then begin
        result:=NewAlt(result,Node);
       end else begin
        result:=Node;
       end;
       Range:=Range.Next;
      end;
     end else begin
      result:=NewNode(ntCHAR,nil,nil,nil,0);
      result^.CharClass:=[];
      Range:=UnicodeCharClass.First;
      while assigned(Range) and (Range.Lo<256) do begin
       if Range.Lo=Range.Hi then begin
        Include(result^.CharClass,ansichar(byte(Range.Lo)));
       end else begin
        if Range.Hi<256 then begin
         result^.CharClass:=result^.CharClass+[ansichar(byte(Range.Lo))..ansichar(byte(Range.Hi))];
        end else begin
         result^.CharClass:=result^.CharClass+[ansichar(byte(Range.Lo))..#$ff];
        end;
       end;
       Range:=Range.Next;
      end;
     end;
    end;
   end;
   function TestClassPOSIXCharacterClass:boolean;
   var LocalSourcePosition,i:longint;
   begin
    result:=false;
    LocalSourcePosition:=SourcePosition;
  
    if (LocalSourcePosition<=SourceLength) and (Source[LocalSourcePosition]='[') then begin
     inc(LocalSourcePosition);
    end else begin
     exit;
    end;
  
    if (LocalSourcePosition<=SourceLength) and (Source[LocalSourcePosition]=':') then begin
     inc(LocalSourcePosition);
    end else begin
     exit;
    end;
  
    if (LocalSourcePosition<=SourceLength) and (Source[LocalSourcePosition]='^') then begin
     inc(LocalSourcePosition);
    end else begin
     exit;
    end;
  
    i:=0;
    while (LocalSourcePosition<=SourceLength) and (Source[LocalSourcePosition] in ['a'..'z','A'..'Z','0'..'9','_','-']) do begin
     inc(LocalSourcePosition);
    end;
    if i=0 then begin
     exit;
    end;
  
    if (LocalSourcePosition<=SourceLength) and (Source[LocalSourcePosition]=':') then begin
     inc(LocalSourcePosition);
    end else begin
     exit;
    end;
  
    if (LocalSourcePosition<=SourceLength) and (Source[LocalSourcePosition]=']') then begin
     inc(LocalSourcePosition);
    end else begin
     exit;
    end;
  
    result:=true;
   end;
   function ParseClassPOSIXCharacterClass(const UnicodeCharClass:TFLREUnicodeCharClass;const CanBeAlreadyCanonicalized:boolean):boolean;
   var Name:ansistring;
       Negate,IgnoreCase:boolean;
   begin
    result:=false;
  
    IgnoreCase:=CanBeAlreadyCanonicalized and (rfCASEINSENSITIVE in Flags);
  
    if (SourcePosition<=SourceLength) and (Source[SourcePosition]='[') then begin
     inc(SourcePosition);
    end else begin
     raise EFLRE.Create('Syntax error');
    end;
  
    if (SourcePosition<=SourceLength) and (Source[SourcePosition]=':') then begin
     inc(SourcePosition);
    end else begin
     raise EFLRE.Create('Syntax error');
    end;
  
    if (SourcePosition<=SourceLength) and (Source[SourcePosition]='^') then begin
     inc(SourcePosition);
     Negate:=true;
    end else begin
     Negate:=false;
    end;
  
    Name:='';
    while (SourcePosition<=SourceLength) and (Source[SourcePosition] in ['a'..'z','A'..'Z','0'..'9','_','-']) do begin
     Name:=Name+Source[SourcePosition];
     inc(SourcePosition);
    end;
  
    if (SourcePosition<=SourceLength) and (Source[SourcePosition]=':') then begin
     inc(SourcePosition);
    end else begin
     raise EFLRE.Create('Syntax error');
    end;
  
    if (SourcePosition<=SourceLength) and (Source[SourcePosition]=']') then begin
     inc(SourcePosition);
    end else begin
     raise EFLRE.Create('Syntax error');
    end;
  
    GetCharClassPerName(Name,UnicodeCharClass,IgnoreCase);
    if Negate then begin
     UnicodeCharClass.Invert;
     UnicodeCharClass.Inverted:=false;
    end;
  
    result:=true;
   end;
   function ParseClassEscapeUnicodeProperty(const UnicodeCharClass:TFLREUnicodeCharClass;const CanBeAlreadyCanonicalized:boolean):boolean;
   var Identifier:ansistring;
       i:longword;
       IgnoreCase,IsNegative:boolean;
       f,LastSourcePos,UntilSourcePos:longint;
   begin
    result:=false;
    if SourcePosition<=SourceLength then begin
     IgnoreCase:=CanBeAlreadyCanonicalized and (rfCASEINSENSITIVE in Flags);
     case Source[SourcePosition] of
      'a'..'z','A'..'Z':begin
       f:=UnicodeClassHashMap.GetValue(UTF32CharToUTF8(UnicodeToLower(byte(ansichar(Source[SourcePosition])))));
       if f>=0 then begin
        inc(SourcePosition);
        UnicodeCharClass.AddUnicodeCategory(f,IgnoreCase);
        result:=true;
       end;
      end;
      '{':begin
       LastSourcePos:=SourcePosition;
       inc(SourcePosition);
       if (SourcePosition<=SourceLength) and (Source[SourcePosition]='^') then begin
        LastSourcePos:=SourcePosition;
        inc(SourcePosition);
        IsNegative:=true;
        IgnoreCase:=false;
       end else begin
        IsNegative:=false;
       end;
       UntilSourcePos:=LastSourcePos;
       while (SourcePosition<=SourceLength) and (Source[SourcePosition] in ['a'..'z','A'..'Z','0'..'9','_','-']) do begin
        UntilSourcePos:=SourcePosition;
        inc(SourcePosition);
       end;
       if (LastSourcePos<UntilSourcePos) and ((SourcePosition<=SourceLength) and (Source[SourcePosition]='}')) then begin
        Identifier:=UTF8LowerCase(copy(Source,LastSourcePos,UntilSourcePos-LastSourcePos));
        inc(SourcePosition);
        GetCharClassPerName(Identifier,UnicodeCharClass,IgnoreCase);
        if IsNegative and assigned(UnicodeCharClass.First) then begin
         UnicodeCharClass.Invert;
         UnicodeCharClass.Inverted:=false;
         if CanBeAlreadyCanonicalized and (rfCASEINSENSITIVE in Flags) then begin
          UnicodeCharClass.Canonicalize;
         end;
        end;
        result:=true;
       end;
      end;
     end;
    end;
   end;
   function ParseClassEscape(const CanBeAlreadyCanonicalized:boolean):TFLREUnicodeCharClass;
   var i:longint;
       IgnoreCase:boolean;
       UnicodeChar:longword;
   begin
    result:=nil;
    try
     IgnoreCase:=CanBeAlreadyCanonicalized and (rfCASEINSENSITIVE in Flags);
     result:=TFLREUnicodeCharClass.Create(self);
     if (SourcePosition<=SourceLength) and (Source[SourcePosition] in ['0'..'9']) then begin
      i:=0;
      while (SourcePosition<=SourceLength) and (Source[SourcePosition] in ['0'..'9']) do begin
       i:=(i*10)+longint(byte(ansichar(Source[SourcePosition]))-byte(ansichar('0')));
       inc(SourcePosition);
      end;
      if i<>0 then begin
       raise EFLRE.Create('Syntax error');
      end;
      result.AddChar(i,IgnoreCase);
      result.Canonicalized:=IgnoreCase;
      exit;
     end;
     case Source[SourcePosition] of
      'a':begin
       inc(SourcePosition);
       result.AddChar($0007,IgnoreCase);
       result.Canonicalized:=true;
      end;
      'b':begin
       inc(SourcePosition);
       result.AddChar($0008,IgnoreCase);
       result.Canonicalized:=true;
      end;
      'B':begin
       inc(SourcePosition);
       result.AddChar(ord('\'),IgnoreCase);
       result.Canonicalized:=true;
      end;
      't':begin
       inc(SourcePosition);
       result.AddChar(9,IgnoreCase);
       result.Canonicalized:=true;
      end;
      'n':begin
       inc(SourcePosition);
       result.AddChar(10,IgnoreCase);
       result.Canonicalized:=true;
      end;
      'v':begin
       inc(SourcePosition);
       result.AddChar(11,IgnoreCase);
       result.Canonicalized:=true;
      end;
      'f':begin
       inc(SourcePosition);
       result.AddChar(12,IgnoreCase);
       result.Canonicalized:=true;
      end;
      'r':begin
       inc(SourcePosition);
       result.AddChar(13,IgnoreCase);
       result.Canonicalized:=true;
      end;
      'e':begin
       inc(SourcePosition);
       result.AddChar($1b,IgnoreCase);
       result.Canonicalized:=true;
      end;
      'w','W':begin
       if rfUTF8 in Flags then begin
        for i:=0 to length(UnicodeCharRangeClasses[ucrWORDS])-1 do begin
         result.AddRange(UnicodeCharRangeClasses[ucrWORDS,i,0],UnicodeCharRangeClasses[ucrWORDS,i,1],IgnoreCase);
        end;
       end else begin
        result.AddRange(ord('a'),ord('z'),IgnoreCase);
        result.AddRange(ord('A'),ord('Z'),IgnoreCase);
        result.AddRange(ord('0'),ord('9'),IgnoreCase);
        result.AddChar(ord('_'),IgnoreCase);
       end;
       if Source[SourcePosition]='W' then begin
        result.Invert;
        result.Inverted:=false;
       end;
       result.Canonicalized:=true;
       inc(SourcePosition);
      end;
      's','S':begin
       if rfUTF8 in Flags then begin
        for i:=0 to length(UnicodeCharRangeClasses[ucrWHITESPACES])-1 do begin
         result.AddRange(UnicodeCharRangeClasses[ucrWHITESPACES,i,0],UnicodeCharRangeClasses[ucrWHITESPACES,i,1],IgnoreCase);
        end;
       end else begin
        result.AddRange(9,13,IgnoreCase);
        result.AddChar(32,IgnoreCase);
       end;
       if Source[SourcePosition]='S' then begin
        result.Invert;
        result.Inverted:=false;
       end;
       result.Canonicalized:=true;
       inc(SourcePosition);
      end;
      'd','D':begin
       if rfUTF8 in Flags then begin
        for i:=0 to length(UnicodeCharRangeClasses[ucrDIGITS])-1 do begin
         result.AddRange(UnicodeCharRangeClasses[ucrDIGITS,i,0],UnicodeCharRangeClasses[ucrDIGITS,i,1],IgnoreCase);
        end;
       end else begin
        result.AddRange(ord('0'),ord('9'),IgnoreCase);
       end;
       if Source[SourcePosition]='D' then begin
        result.Invert;
        result.Inverted:=false;
       end;
       result.Canonicalized:=true;
       inc(SourcePosition);
      end;
      'p':begin
       inc(SourcePosition);
       if ParseClassEscapeUnicodeProperty(result,CanBeAlreadyCanonicalized) then begin
        result.Canonicalized:=true;
       end else begin
        raise EFLRE.Create('Syntax error');
       end;
      end;
      'P':begin
       inc(SourcePosition);
       if ParseClassEscapeUnicodeProperty(result,CanBeAlreadyCanonicalized) then begin
        result.Canonicalized:=true;
       end else begin
        raise EFLRE.Create('Syntax error');
       end;
       result.Invert;
       result.Inverted:=false;
       result.Canonicalized:=true;
      end;
      'c':begin
       inc(SourcePosition);
       if (SourcePosition<=SourceLength) and (Source[SourcePosition] in ['a'..'z','A'..'Z']) then begin
        case Source[SourcePosition] of
         'a'..'z':begin
          result.AddChar(byte(ansichar(Source[SourcePosition]))-byte(ansichar('a')),IgnoreCase);
         end;
         'A'..'Z':begin
          result.AddChar(byte(ansichar(Source[SourcePosition]))-byte(ansichar('A')),IgnoreCase);
         end;
        end;
        result.Canonicalized:=IgnoreCase;
       end else begin
        raise EFLRE.Create('Syntax error');
       end;
      end;
      'x':begin
       inc(SourcePosition);
       if ((SourcePosition+1)<=SourceLength) and
          (Source[SourcePosition+0] in ['0'..'9','a'..'f','A'..'F']) and
          (Source[SourcePosition+1] in ['0'..'9','a'..'f','A'..'F']) then begin
        result.AddChar((Hex2Value(Source[SourcePosition+0]) shl 8) or Hex2Value(Source[SourcePosition+1]),IgnoreCase);
        inc(SourcePosition,2);
       end else if (SourcePosition<=SourceLength) and (Source[SourcePosition]='{') then begin
        inc(SourcePosition);
        UnicodeChar:=0;
        while (SourcePosition<=SourceLength) and (Source[SourcePosition] in ['0'..'9','a'..'f','A'..'F']) do begin
         UnicodeChar:=(UnicodeChar shl 4) or Hex2Value(Source[SourcePosition]);
         inc(SourcePosition);
        end;
        if (SourcePosition<=SourceLength) and (Source[SourcePosition]='}') then begin
         inc(SourcePosition);
         result.AddChar(UnicodeChar,IgnoreCase);
        end else begin
         raise EFLRE.Create('Syntax error');
        end;
       end else begin
        raise EFLRE.Create('Syntax error');
       end;
      end;
      'u':begin
       inc(SourcePosition);
       if ((SourcePosition+3)<=SourceLength) and
          (Source[SourcePosition+0] in ['0'..'9','a'..'f','A'..'F']) and
          (Source[SourcePosition+1] in ['0'..'9','a'..'f','A'..'F']) and
          (Source[SourcePosition+2] in ['0'..'9','a'..'f','A'..'F']) and
          (Source[SourcePosition+3] in ['0'..'9','a'..'f','A'..'F']) then begin
        UnicodeChar:=(Hex2Value(Source[SourcePosition+0]) shl 24) or (Hex2Value(Source[SourcePosition+1]) shl 16) or (Hex2Value(Source[SourcePosition+2]) shl 8) or Hex2Value(Source[SourcePosition+3]);
        inc(SourcePosition,4);
        result.AddChar(UnicodeChar,IgnoreCase);
       end else begin
        raise EFLRE.Create('Syntax error');
       end;
      end;
      'U':begin
       inc(SourcePosition);
       if (SourcePosition<=SourceLength) and (Source[SourcePosition] in ['0'..'9','a'..'f','A'..'F']) then begin
        UnicodeChar:=0;
        while (SourcePosition<=SourceLength) and (Source[SourcePosition] in ['0'..'9','a'..'f','A'..'F']) do begin
         UnicodeChar:=(UnicodeChar shl 4) or Hex2Value(Source[SourcePosition]);
         inc(SourcePosition);
        end;
        result.AddChar(UnicodeChar,IgnoreCase);
       end else begin
        raise EFLRE.Create('Syntax error');
       end;
      end;
      'Q':begin
       inc(SourcePosition);
       while SourcePosition<=SourceLength do begin
        if Source[SourcePosition]='\' then begin
         inc(SourcePosition);
         if (SourcePosition<=SourceLength) and (Source[SourcePosition]='E') then begin
          inc(SourcePosition);
          break;
         end else begin
          result.AddChar(ord('\'),IgnoreCase);
         end;
        end else begin
         if (rfUTF8 in Flags) and (byte(ansichar(Source[SourcePosition]))>=$80) then begin
          UnicodeChar:=UTF8CodeUnitGetCharAndIncFallback(Source,SourcePosition);
          result.AddChar(UnicodeChar,IgnoreCase);
         end else begin
          result.AddChar(byte(ansichar(Source[SourcePosition])),IgnoreCase);
          inc(SourcePosition);
         end;
        end;
       end;
       result.Canonicalized:=IgnoreCase;
      end;
      else begin
       if (rfUTF8 in Flags) and (byte(ansichar(Source[SourcePosition]))>=$80) then begin
        UnicodeChar:=UTF8CodeUnitGetCharAndIncFallback(Source,SourcePosition);
        result.AddChar(UnicodeChar,IgnoreCase);
       end else begin
        result.AddChar(byte(ansichar(Source[SourcePosition])),IgnoreCase);
        inc(SourcePosition);
       end;
      end;
     end;
    except
     FreeAndNil(result);
     raise;
    end;
   end;
   function ParseClassAtom:TFLREUnicodeCharClass;
   begin
    result:=nil;
    try
     if SourcePosition<=SourceLength then begin
      if Source[SourcePosition]='\' then begin
       inc(SourcePosition);
       result:=ParseClassEscape(false);
      end else if TestClassPOSIXCharacterClass then begin
       result:=TFLREUnicodeCharClass.Create(self);
       if not ParseClassPOSIXCharacterClass(result,false) then begin
        raise EFLRE.Create('Syntax error');
       end;
      end else begin
       result:=TFLREUnicodeCharClass.Create(self);
       if (rfUTF8 in Flags) and (byte(ansichar(Source[SourcePosition]))>=$80) then begin
        result.AddChar(UTF8CodeUnitGetCharAndIncFallback(Source,SourcePosition));
       end else begin
        result.AddChar(byte(ansichar(Source[SourcePosition])));
        inc(SourcePosition);
       end;
      end;
     end else begin
      raise EFLRE.Create('Syntax error');
     end;
    except
     FreeAndNil(result);
     raise;
    end;
   end;
   function ParseCharacterClass:TFLREUnicodeCharClass;
   var InvertFlag:boolean;
       a,b,c:TFLREUnicodeCharClass;
   begin
    result:=nil;
    try
     a:=nil;
     b:=nil;
     try
      result:=TFLREUnicodeCharClass.Create(self);
      if (SourcePosition<=SourceLength) and (Source[SourcePosition]='[') then begin
       inc(SourcePosition);
      end else begin
       raise EFLRE.Create('Syntax error');
      end;
      if (SourcePosition<=SourceLength) and (Source[SourcePosition]='^') then begin
       inc(SourcePosition);
       InvertFlag:=true;
      end else begin
       InvertFlag:=false;
      end;
      while (SourcePosition<=SourceLength) and (Source[SourcePosition]<>']') do begin
       if ((SourcePosition+1)<=SourceLength) and ((Source[SourcePosition]='-') and (Source[SourcePosition+1] in ['[',']'])) then begin
        inc(SourcePosition);
        if Source[SourcePosition]=']' then begin
         a:=TFLREUnicodeCharClass.Create(self);
         a.AddChar(ord('-'));
        end else begin
         a:=ParseCharacterClass;
         b:=TFLREUnicodeCharClass.Create(self);
         if b.Subtraction(result,a) then begin
          FreeAndNil(result);
          result:=b;
          b:=nil;
         end else begin
          FreeAndNil(b);
         end;
         FreeAndNil(a);
         if not ((SourcePosition<=SourceLength) and (Source[SourcePosition]=']')) then begin
          raise EFLRE.Create('Syntax error');
         end;
         continue;
        end;
       end else begin
        a:=ParseClassAtom;
       end;
       if ((SourcePosition+1)<=SourceLength) and ((Source[SourcePosition]='&') and (Source[SourcePosition+1]='&')) then begin
        inc(SourcePosition,2);
        if (SourcePosition<=SourceLength) and (Source[SourcePosition] in ['[',']']) then begin
         if Source[SourcePosition]='[' then begin
          if assigned(a) then begin
           result.TakeoverCombine(a);
           FreeAndNil(a);
          end;
          a:=ParseCharacterClass;
          b:=TFLREUnicodeCharClass.Create(self);
          if b.Intersection(result,a) then begin
           FreeAndNil(result);
           result:=b;
           b:=nil;
          end else begin
           FreeAndNil(b);
          end;
          FreeAndNil(a);
          if not ((SourcePosition<=SourceLength) and (Source[SourcePosition]=']')) then begin
           raise EFLRE.Create('Syntax error');
          end;
          continue;
         end else begin
          raise EFLRE.Create('Syntax error');
         end;
        end else begin
         raise EFLRE.Create('Syntax error');
        end;
       end else if (SourcePosition<=SourceLength) and (Source[SourcePosition]='-') then begin
        inc(SourcePosition);
        if (SourcePosition<=SourceLength) and (Source[SourcePosition] in ['[',']']) then begin
         if Source[SourcePosition]='[' then begin
          if assigned(a) then begin
           result.TakeoverCombine(a);
           FreeAndNil(a);
          end;
          a:=ParseCharacterClass;
          b:=TFLREUnicodeCharClass.Create(self);
          if b.Subtraction(result,a) then begin
           FreeAndNil(result);
           result:=b;
           b:=nil;
          end else begin
           FreeAndNil(b);
          end;
          FreeAndNil(a);
          if not ((SourcePosition<=SourceLength) and (Source[SourcePosition]=']')) then begin
           raise EFLRE.Create('Syntax error');
          end;
          continue;
         end else begin
          a.AddChar(ord('-'));
         end;
        end else if assigned(a) then begin
         if not a.IsSingle then begin
          if assigned(a.Last) and (a.Last.Lo<=a.Last.Hi) then begin
           c:=TFLREUnicodeCharClass.Create(self);
           c.AddChar(a.Last.Hi);
           c.Canonicalized:=a.Canonicalized;
           c.Inverted:=a.Inverted;
           result.TakeoverCombine(a);
           FreeAndNil(a);
           a:=c;
          end else begin
           FreeAndNil(a);
           raise EFLRE.Create('Syntax error');
          end;
         end;
         b:=ParseClassAtom;
         if (not b.IsSingle) and (assigned(b.First) and (a.First.Lo<=a.First.Hi)) then begin
          c:=TFLREUnicodeCharClass.Create(self);
          c.AddChar(b.First.Lo);
          c.Canonicalized:=b.Canonicalized;
          c.Inverted:=b.Inverted;
          result.TakeoverCombine(b);
          FreeAndNil(b);
          b:=c;
         end;
         if (not b.IsSingle) or ((assigned(a.Last) and assigned(b.Last)) and not (a.Last.Lo<=b.Last.Hi)) then begin
          FreeAndNil(a);
          FreeAndNil(b);
          raise EFLRE.Create('Syntax error');
         end;
         if assigned(a.Last) and assigned(b.Last) then begin
          a.Last.Hi:=b.Last.Hi;
         end else begin
          a.TakeoverCombine(b);
         end;
         FreeAndNil(b);
        end;
       end;
       if assigned(a) then begin
        result.TakeoverCombine(a);
        FreeAndNil(a);
       end;
      end;
      if (SourcePosition<=SourceLength) and (Source[SourcePosition]=']') then begin
       inc(SourcePosition);
      end else begin
       raise EFLRE.Create('Syntax error');
      end;
      if (rfCASEINSENSITIVE in Flags) and not result.Canonicalized then begin
       result.Canonicalize;
      end;
      if InvertFlag then begin
       result.Invert;
      end;
     finally
      FreeAndNil(a);
      FreeAndNil(b);
     end;
    except
     FreeAndNil(result);
     raise;
    end;
   end;
   function ParseAtom:PFLRENode;
   var Value,Index:longint;
       Negate,IsSingle,Done,IsNegative,First,Num:boolean;
       StartChar,EndChar,UnicodeChar,LowerCaseUnicodeChar,UpperCaseUnicodeChar:longword;
       UnicodeCharClass:TFLREUnicodeCharClass;
       OldFlags:TFLREFlags;
       Name:ansistring;
   begin
    result:=nil;
    try
  