class TestCase::Regex {
  use Regex;
  use Regex::ReplaceInfo;
  use StringBuffer;
  use Re;
  
  static method new : int () {
    
    {
      my $re = Regex->new("abc");
    }
    
    # Exceptions
    {
      # Invalid regex
      {
        eval { Regex->new(")abc"); };
        unless ($@) {
          return 0;
        }
        
        eval { Regex->new("((abc)"); };
        unless ($@) {
          return 0;
        }
      }
    }
    return 1;
  }

  static method replace_g : int () {
    # Replace all
    {
      my $re = Regex->new("abc");
      my $target = copy "ppzabczabcz";
      my $offset = 0;
      my $length = -1;
      my $replace_info = $re->replace_g((mutable string)$target, "ABC", \$offset, $length);
      
      unless ($replace_info->replaced_count == 2) {
        return 0;
      }
      
      unless ($target eq "ppzABCzABCz") {
        return 0;
      }
    }

    # Replace all offset
    {
      my $re = Regex->new("abc");
      my $target = copy "ppzabczabczabcz";
      my $offset = 6;
      my $length = -1;
      
      my $replace_info = $re->replace_g((mutable string)$target, "ABC", \$offset, $length);
      unless ($replace_info->replaced_count == 2) {
        return 0;
      }
      
      unless ($target eq "ppzabczABCzABCz") {
        return 0;
      }
    }

    # Replace all with number
    {
      my $re = Regex->new("a\d+b");
      my $target = copy "za123bz";
      my $offset = 0;
      my $length = -1;
      
      my $replace_info = $re->replace_g((mutable string)$target, "ABC", \$offset, $length);
      
      unless ($replace_info->replaced_count == 1) {
        return 0;
      }
      
      unless ($target eq "zABCz") {
        return 0;
      }
    }

    # Replace all - Not replace_g
    {
      my $re = Regex->new("a\d+b");
      my $target = copy "pppp";
      my $offset = 0;
      my $length = -1;
      
      my $replace_info = $re->replace_g((mutable string)$target, "ABC", \$offset, $length);
      
      if ($replace_info) {
        return 0;
      }
      
      unless ($target eq "pppp") {
        return 0;
      }
    }
    
    return 1;
  }
  
  static method replace_common : int () {
    # Replace
    {
      my $re = Regex->new("abc");
      my $target = copy "ppzabcz";
      my $offset = 0;
      
      my $replace_info = $re->replace((mutable string)$target, "ABC", \$offset, -1);
      
      unless ($replace_info->replaced_count == 1) {
        return 0;
      }
      
      unless ($target eq "ppzABCz") {
        return 0;
      }
    }
    
    # Replace offset
    {
      my $re = Regex->new("abc");
      my $target = copy "ppzabczabczabcz";
      my $offset = 6;
      
      my $replace_info = $re->replace((mutable string)$target, "ABC", \$offset, -1);
      
      unless ($replace_info->replaced_count == 1) {
        return 0;
      }
      
      unless ($target eq "ppzabczABCzabcz") {
        return 0;
      }
    }
    
    # Replace with number
    {
      my $re = Regex->new("a\d+b");
      my $target = copy "za123bz";
      my $offset = 0;
      
      my $replace_info = $re->replace((mutable string)$target, "ABC", \$offset, -1);
      my $result = $target;
      
      unless ($replace_info->replaced_count == 1) {
        return 0;
      }
      
      unless ($target eq "zABCz") {
        return 0;
      }
    }
    
    # Replace - Not replaced
    {
      my $re = Regex->new("a\d+b");
      my $target = copy "pppp";
      my $offset = 0;
      
      my $replace_info = $re->replace((mutable string)$target, "ABC", \$offset, -1);
      my $result = $target;
      
      if ($replace_info) {
        return 0;
      }
      
      unless ($target eq "pppp") {
        return 0;
      }
    }
    
    return 1;
  }
  
  static method replace : int () {
    # Replace
    {
      my $re = Regex->new("abc");
      my $target = copy "ppzabcz";
      
      $re->replace((mutable string)$target, "ABC");
      my $result = $target;
      
      unless ($target eq "ppzABCz") {
        return 0;
      }
    }
    
    # Replace offset
    {
      my $re = Regex->new("abc");
      my $target = copy "ppzabczabczabcz";
      my $offset = 6;
      
      $re->replace((mutable string)$target, "ABC", \$offset);
      my $result = $target;
      
      unless ($target eq "ppzabczABCzabcz") {
        return 0;
      }
    }
    
    # Replace - capture
    {
      my $re = Regex->new("^(\d+)a(\d+)$");
      my $target = copy "123a456";
      my $offset = 0;
      my $length = -1;
      
      my $replace_info = $re->replace((mutable string)$target, "", \$offset, $length);
      my $result = $target;
      
      unless ($replace_info->match->cap1 eq "123") {
        return 0;
      }
      
      unless ($replace_info->match->cap2 eq "456") {
        return 0;
      }
      
      unless ($target eq "") {
        return 0;
      }
    }
    
    # Replace offset \A
    {
      my $target = copy "zabcabcz";
      my $offset = 1;
      my $length = 6;
      
      Re->s((mutable string)$target, ["\Aabc", "g"], "ABC", \$offset);
      
      unless ($target eq "zABCabcz") {
        diag $target;
        return 0;
      }
    }
    
    # Replace length \z
    {
      my $target = copy "zabcabcz";
      my $offset = 1;
      my $length = 6;
      
      Re->s((mutable string)$target, ["abc\z", "g"], "ABC", \$offset, $length);
      
      unless ($target eq "zabcABCz") {
        diag $target;
        return 0;
      }
    }
    
    return 1;
  }
  
  static method replace_cb : int () {
    # Replace callback with capture
    {
      my $re = Regex->new("a(bc)");
      my $target = copy "ppzabcz";
      my $offset = 0;
      
      my $replace_info = $re->replace((mutable string)$target, method : string ($re : Regex, $match : Regex::Match) {
        return "AB" . $match->cap(1) . "C";
      }, \$offset, -1);
      my $result = $target;
      
      unless ($replace_info->replaced_count == 1) {
        return 0;
      }
      
      unless ($target eq "ppzABbcCz") {
        return 0;
      }
    }
    return 1;
  }
  
  static method match_start_and_end : int () {
    # Match start and end
    {
      my $re = Regex->new("abc");
      my $target = copy "ppzabcz";
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
      
      unless ($match->match_start == 3) {
        return 0;
      }
      unless ($match->match_length == 3) {
        return 0;
      }
    }

    # Match start UTF-8
    {
      my $re = Regex->new("あい[かきくけこ]+う");
      my $target = copy "んんあいかくこうん";
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
      
      unless ($match->match_start == 6) {
        return 0;
      }
      unless ($match->match_length == 18) {
        return 0;
      }
    }

    # Match start zero width
    {
      my $re = Regex->new("b*c");
      my $target = copy "zzcz";
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
      
      unless ($match->match_start == 2) {
        return 0;
      }
      unless ($match->match_length == 1) {
        return 0;
      }
    }


    # Match start zero width only
    {
      my $re = Regex->new("b*");
      my $target = copy "zzcz";
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
      
      unless ($match->match_start == 0) {
        return 0;
      }
      unless ($match->match_length == 0) {
        return 0;
      }
    }
    
    return 1;
  }
  
  static method match_capture : int ()  {
    # Capture zero more only
    {
      my $re = Regex->new("(a*)");
      my $target = copy "aaa";
      my $match = $re->match($target);
      unless ($match->cap(1) eq "aaa") {
        return 0;
      }
    }
    
    # Capture a char
    {
      my $re = Regex->new("a(b)c");
      my $target = copy "zabcz";
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
      
      unless ($match->cap(1) eq "b") {
        return 0;
      }
    }

    # Capture a char UTF-8
    {
      my $re = Regex->new("あ(い)う");
      my $target = copy "んあいうん";
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
      
      unless ($match->cap(1) eq "い") {
        return 0;
      }
    }

    # Capture a char zero width
    {
      my $re = Regex->new("a(b?)c");
      my $target = copy "zacz";
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
      
      unless ($match->cap(1) eq "") {
        return 0;
      }
    }

    # Capture char class-and quantifier
    {
      my $re = Regex->new("\-(\w+)\-");
      my $target = copy "-abc89-";
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }

      
      unless ($match->cap(1) eq "abc89") {
        return 0;
      }
    }

    # Capture many strings 
    {
      my $re = Regex->new("\-(\w+) (\w+) (\w+) (\w+) (\w+)");
      my $target = copy "-abc1 abc2 abc3 abc4 abc5 abc6-";
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
      
      unless ($match->cap(1) eq "abc1") {
        return 0;
      }

      unless ($match->cap(2) eq "abc2") {
        return 0;
      }

      unless ($match->cap(3) eq "abc3") {
        return 0;
      }

      unless ($match->cap(4) eq "abc4") {
        return 0;
      }

      unless ($match->cap(5) eq "abc5") {
        return 0;
      }
    }

    # Capture zero more only
    {
      my $re = Regex->new("(a*)");
      my $target = copy "aaa";
      my $match = $re->match($target);
      unless ($match->cap(1) eq "aaa") {
        return 0;
      }
    }
    
    return 1;
  }
  
  static method match_char_class_range : int ()  {
    # Match char class-range
    {
      my $re = Regex->new("[0-9]+");
      my $target = copy "z09az";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # Not Match char class-range
    {
      my $re = Regex->new("[0-9a-c]+");
      my $target = copy "zz";
      
      my $match = $re->match($target);
      
      if ($match) {
        return 0;
      }
    }
    
    # .
    {
      my $re = Regex->new("(.+)");
      my $target = copy "abc\ndef";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
      
      unless ($match->cap(1) eq "abc") {
        return 0;
      }
    }
    
    # . - single line mode
    {
      my $re = Regex->new("(.+)", "s");
      my $target = copy "abc\ndef";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
      
      unless ($match->cap(1) eq "abc\ndef") {
        return 0;
      }
    }

    return 1;
  }

  static method match_char_class_negate : int () {

    # Match char class-negate
    {
      my $re = Regex->new("[^0-9]+");
      my $target = copy "zabcz";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # Not match char class-negate
    {
      my $re = Regex->new("[^0-9]+");
      my $target = copy "012";
      
      my $match = $re->match($target);
      
      if ($match) {
        return 0;
      }
    }

    # Match char class-negate UTF-8
    {
      my $re = Regex->new("[^あ]+");
      my $target = copy "いうえ";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # Don't Match char class-negate UTF-8
    {
      my $re = Regex->new("[^あ]+");
      my $target = copy "あああ";
      
      my $match = $re->match($target);
      
      if ($match) {
        return 0;
      }
    }

    return 1;
  }
  
  static method match_char_class : int () {

    # Match char class
    {
      {
        my $re = Regex->new("[bcdあ]+");
        my $target = copy "zabcあz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
      
      {
        my $re = Regex->new("^[a-c\dx-z]+$");
        my $target = copy "ac09xz";
        my $match = $re->match($target);
        unless ($match) {
          return 0;
        }
      }
    }

    # Match char class-\d
    {
      my $re = Regex->new("[\da]+");
      my $target = copy "z01az";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # Not Match char class
    {
      my $re = Regex->new("[bcd\d]+");
      my $target = copy "ae";
      
      my $match = $re->match($target);
      
      if ($match) {
        return 0;
      }
    }

    # ^[\d\D]+
    {
      my $re = Regex->new("^[\d\D]+$");
      
      my $target = copy "abc123";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # ^[^\d\D]+
    {
      my $re = Regex->new("^[^\d\D]+$");
      
      {
        my $target = copy "abc";
        
        my $match = $re->match($target);
        if ($match) {
          return 0;
        }
      }
      {
        my $target = copy "123";
        
        my $match = $re->match($target);
        if ($match) {
          return 0;
        }
      }
    }

    # [a-a] | "-" is a character unless "-" is used as a charcter class range
    {
      my $re = Regex->new("[a-a]");
      
      {
        my $target = copy "a";
        my $match = $re->match($target);
        unless ($match) {
          return 0;
        }
      }
    }
    
    # [a-aa-a] | "-" is a character unless "-" is used as a charcter class range
    {
      my $re = Regex->new("[a-aa-a]");
      
      {
        my $target = copy "a";
        my $match = $re->match($target);
        unless ($match) {
          return 0;
        }
      }
    }

    # - | "-" is a character unless "-" is used as a charcter class range
    {
      {
        my $re = Regex->new("-");
        
        {
          my $target = copy "-";
          my $match = $re->match($target);
          unless ($match) {
            return 0;
          }
        }
      }
      {
        my $re = Regex->new("a-z");
        
        {
          my $target = copy "a-z";
          my $match = $re->match($target);
          unless ($match) {
            return 0;
          }
        }
      }
      
    }

    # [-] | "-" is a character unless "-" is used as a charcter class range
    {
      my $re = Regex->new("[-]");
      
      {
        my $target = copy "-";
        my $match = $re->match($target);
        unless ($match) {
          return 0;
        }
      }
    }

    # [a-] | "-" is a character unless "-" is used as a charcter class range
    {
      my $re = Regex->new("[a-]");
      
      {
        my $target = copy "a";
        my $match = $re->match($target);
        unless ($match) {
          return 0;
        }
      }

      {
        my $target = copy "-";
        my $match = $re->match($target);
        unless ($match) {
          return 0;
        }
      }
    }

    # Invalid character class range
    {
      eval { Regex->new("[z-a]"); };
      
      unless ($@) {
        return 0;
      }
    }

    # [ ^a]
    {
      my $re = Regex->new("[ ^a]");
      
      {
        my $target = copy " ";
        my $match = $re->match($target);
        unless ($match) {
          return 0;
        }
      }
      {
        my $target = copy "^";
        my $match = $re->match($target);
        unless ($match) {
          return 0;
        }
      }
      {
        my $target = copy "a";
        my $match = $re->match($target);
        unless ($match) {
          return 0;
        }
      }
    }
    
    
    
    return 1;
  }

  static method match_not_space : int () {

    # Match not space
    {
      my $re = Regex->new("\s+\S+\s+");
      my $target = copy "\f\tzacz \r\n";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # Not Match not space
    {
      my $re = Regex->new("\S+");
      my $target = copy "\f\t \r\n";
      
      my $match = $re->match($target);
      
      if ($match) {
        return 0;
      }
    }
    
    return 1;
  }
  static method match_space : int () {

    # Match space
    {
      my $re = Regex->new("a\s+c");
      my $target = copy "za\f\t\r\n cz";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # Not Match
    {
      my $re = Regex->new("\s+");
      my $target = copy "\aabc\0";
      
      my $match = $re->match($target);
      
      if ($match) {
        return 0;
      }
    }
    
    return 1;
  }

  static method match_not_word : int () {

    # Match not number
    {
      my $re = Regex->new("\w\W+\w");
      my $target = copy "0-:9";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }
    
    # Match not a-z
    {
      my $re = Regex->new("\w\W+\w");
      my $target = copy "ab`{yz";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # Match not A-Z
    {
      my $re = Regex->new("\w\W+\w");
      my $target = copy "AB`{YZ";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # Match not _
    {
      my $re = Regex->new("\w\W+\w");
      my $target = copy "_^`_";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # not Match 
    {
      my $re = Regex->new("\W+");
      my $target = copy "azAZ_09";
      
      my $match = $re->match($target);
      
      if ($match) {
        return 0;
      }
    }
    
    return 1;
  }

  static method match_word : int () {

    # Match number
    {
      my $re = Regex->new("\-\w+\:");
      my $target = copy "-0123456789:";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }
    
    # Match a-z
    {
      my $re = Regex->new("\`\w+\{");
      my $target = copy "`abyz{";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # Match A-Z
    {
      my $re = Regex->new("\`\w+\{");
      my $target = copy "`ABYZ{";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # Match _
    {
      my $re = Regex->new("\^\w+\`");
      my $target = copy "^__`";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # Match Not
    {
      my $re = Regex->new("\w+");
      my $target = copy "{}あいう";
      
      my $match = $re->match($target);
      
      if ($match) {
        return 0;
      }
    }
    
    return 1;
  }

  static method match_not_number : int () {

    # Match not number
    {
      my $re = Regex->new("0\D+9");
      my $target = copy "0abc9";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }
    
    return 1;
  }

  static method match_number : int () {

    # Match number
    {
      my $re = Regex->new("a\d+c");
      my $target = copy "za0123456789cz";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }
    
    # Match number and not number
    {
      {
        my $re = Regex->new("\d+\D+\d+");
        my $target = copy "123abc789";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
    }
    
    return 1;
  }
  
  static method match_start : int () {
    # Match ^
    {
      # Match ^ - "abbcz"
      {
        my $re = Regex->new("^ab+c");
        my $target = copy "abbcz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
      
      # Not Match ^ - "zabbcz"
      {
        my $re = Regex->new("^ab+c");
        my $target = copy "zabbcz";
        
        my $match = $re->match($target);
        
        if ($match) {
          return 0;
        }
      }
      
      # Match \A - "abbcz"
      {
        my $re = Regex->new("\Aab+c");
        my $target = copy "abbcz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
      
      # Match \z - offset + length
      {
        my $re = Regex->new("\Aab+c\z");
        my $target = copy "zabbcz";
        
        my $offset = 1;
        my $length = 4;
        my $match = $re->match($target, \$offset, $length);
        
        unless ($match) {
          return 0;
        }
        
        unless ($offset == 5) {
          diag $offset;
          return 0;
        }
      }
      
    }
    
    return 1;
  }
  
  static method match_end : int () {
    # Match $
    {
      # Match $ - "zabbc"
      {
        my $re = Regex->new("ab+c$");
        my $target = copy "zabbc";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
      
      # Not Match $ - "zabbcz"
      {
        my $re = Regex->new("ab+c$");
        my $target = copy "zabbcz";
        
        my $match = $re->match($target);
        
        if ($match) {
          return 0;
        }
      }
      
      # Match $ - "zabbc"
      {
        my $re = Regex->new("ab+c\z");
        my $target = copy "zabbc";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
      
    }
    
    return 1;
  }

  static method match_quantifier : int () {
    # Match {1,3}
    {
      # Match {1,3} - "zabcz"
      {
        my $re = Regex->new("ab{1,3}c");
        my $target = copy "zabcz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
      
      # Match {1,3} - "zabbbcz"
      {
        my $re = Regex->new("ab{1,3}c");
        my $target = copy "zabbbcz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }

      # Not Match {1,3} - "zacz"
      {
        my $re = Regex->new("ab{1,3}c");
        my $target = copy "zacz";
        
        my $match = $re->match($target);
        
        if ($match) {
          return 0;
        }
      }
      # Not Match {1,3} - "zabbbbcz"
      {
        my $re = Regex->new("ab{1,3}c");
        my $target = copy "zabbbbcz";
        
        my $match = $re->match($target);
        
        if ($match) {
          return 0;
        }
      }
    }

    # Match {11,13}
    {
      # Match {11,13} - "zabbbbbbbbbbbcz"
      {
        my $re = Regex->new("ab{11,13}c");
        my $target = copy "zabbbbbbbbbbbcz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
      
      # Match {11,13} - "zabbbcz"
      {
        my $re = Regex->new("ab{11,13}c");
        my $target = copy "zabbbbbbbbbbbbbcz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }

      # Not Match {11,13} - "zacz"
      {
        my $re = Regex->new("ab{11,13}c");
        my $target = copy "zabbbbbbbbbbcz";
        
        my $match = $re->match($target);
        
        if ($match) {
          return 0;
        }
      }
      # Not Match {11,13} - "zabbbbcz"
      {
        my $re = Regex->new("ab{11,13}c");
        my $target = copy "zabbbbbbbbbbbbbbcz";
        
        my $match = $re->match($target);
        
        if ($match) {
          return 0;
        }
      }
    }

    # {m,}
    {
      my $re = Regex->new("ab{2,}c");
      
      {
        my $target = copy "zabcz";
        
        my $match = $re->match($target);
        
        if ($match) {
          return 0;
        }
      }
      {
        my $target = copy "zabbcz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
      {
        my $target = copy "zabbbcz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
    }
    
    return 1;
  }

  static method match_one_or_zero : int () {
    # Match ?
    {
      # Match ? - "zabcz"
      {
        my $re = Regex->new("ab?c");
        my $target = copy "zabcz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }

      # Not Match ? - "zabbcz"
      {
        my $re = Regex->new("ab?c");
        my $target = copy "zabbcz";
        
        my $match = $re->match($target);
        
        if ($match) {
          return 0;
        }
      }

      # Match ? - "zacz"
      {
        my $re = Regex->new("ab?c");
        my $target = copy "zacz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
    }
    
    return 1;
  }
  
  static method match_one_more : int () {
    # Match +
    {
      # Match + - "zabcz"
      {
        my $re = Regex->new("ab+c");
        my $target = copy "zabcz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }

      # Match + - "zabbcz"
      {
        my $re = Regex->new("ab+c");
        my $target = copy "zabbcz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }

      # Not Match + - "zacz"
      {
        my $re = Regex->new("ab+c");
        my $target = copy "zacz";
        
        my $match = $re->match($target);
        
        if ($match) {
          return 0;
        }
      }
    }
    
    return 1;
  }

  static method match_zero_more : int () {
    # Match *
    {
      # Match * - "zabcz"
      {
        my $re = Regex->new("ab*c");
        my $target = copy "zabcz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }

      # Match * - "zabbcz"
      {
        my $re = Regex->new("ab*c");
        my $target = copy "zabbcz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }

      # Match * - "zacz"
      {
        my $re = Regex->new("ab*c");
        my $target = copy "zacz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }

      # Not Match * - "zabbdz"
      {
        my $re = Regex->new("ab*c");
        my $target = copy "zabbdz";
        
        my $match = $re->match($target);
        
        if ($match) {
          return 0;
        }
      }
    }
    
    return 1;
  }

  static method match_forward : int () {

    # Not Match string
    {
      my $re = Regex->new("abc");
      my $target = copy "zabcz";
      
      my $match = (my $offset = 2, $re->match($target, \$offset));
      
      if ($match) {
        return 0;
      }
    }
    
    # Match string
    {
      my $re = Regex->new("abc");
      my $target = copy "zabcz";
      
      my $match = (my $offset = 1, $re->match($target, \$offset));
      
      unless ($match) {
        return 0;
      }
    }
    
    return 1;
  }

  static method match : int () {

    # Match string
    {
      my $re = Regex->new("abc");
      my $target = copy "zabcz";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }
    
    # Match same string
    {
      my $re = Regex->new("abc");
      my $target = copy "abc";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # ignore case
    {
      {
        my $re = Regex->new("abz", "i");
        my $target = copy "zABZz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }

      {
        my $re = Regex->new("ABZ", "i");
        my $target = copy "zabzz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
      
      {
        my $re = Regex->new("A[B-Z]{2,2}", "i");
        my $target = copy "zabzz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }

      {
        my $re = Regex->new("a[b-z]{2,2}", "i");
        my $target = copy "zABZz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
    }
    
    # Exceptions
    {
      {
        my $re = Regex->new("abc");
        
        eval { my $match = $re->match(undef); }
        
        unless ($@) {
          return 0;
        }
      }
      
    }
    
    return 1;
  }
  
  static method extra : int () {

    {
      my $path = "/..";
      my $match = Regex->new("^/\.\.$")->match($path);
      unless ($match) {
        return 0;
      }
    }

    {
      my $path = copy "/..";
      Regex->new("^/\.\.$")->replace((mutable string)$path, "/");
      
      unless ($path eq "/") {
        return 0;
      }
    }
    
    {
      my $path = "/..";
      my $match = Regex->new("^/\.\.$")->match($path);
      unless ($match) {
        return 0;
      }
    }
    
    # Capture syntax suger
    {
      my $re = Regex->new("(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)");
      
      my $target = copy "12345678910";
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
      
      unless ($match->cap1 eq "1") {
        return 0;
      }
      unless ($match->cap2 eq "2") {
        return 0;
      }
      unless ($match->cap3 eq "3") {
        return 0;
      }
      unless ($match->cap4 eq "4") {
        return 0;
      }
      unless ($match->cap5 eq "5") {
        return 0;
      }
      unless ($match->cap6 eq "6") {
        return 0;
      }
      unless ($match->cap7 eq "7") {
        return 0;
      }
      unless ($match->cap8 eq "8") {
        return 0;
      }
      unless ($match->cap9 eq "9") {
        return 0;
      }
      unless ($match->cap10 eq "10") {
        return 0;
      }
    }
    
    # "]" is a character at the place that is not character class.
    {
      my $re = Regex->new("]");
      my $target = copy "]";
      my $match = $re->match($target);
      unless ($match) {
        return 0;
      }
    }
    
    # Simple
    {
      my $re = Regex->new("c");
      
      my $string = "abc";
      my $match = $re->match($string);
      
      unless ($match) {
        return 0;
      }
    }
    
    # Captures
    {
      my $re = Regex->new("^(\d+):(\d+):(\d+)$");
      
      my $string = "12:34:56";
      my $match = $re->match($string);
      
      unless ($match) {
        return 0;
      }
      
      unless ($match->cap1 eq "12") {
        return 0;
      }
      
      unless ($match->captures->[0] eq "12") {
        return 0;
      }
      
      unless ($match->cap2 eq "34") {
        return 0;
      }
      
      unless ($match->cap3 eq "56") {
        return 0;
      }
      
      unless ($match->captures_length == 3) {
        return 0;
      }
      
    }

    # Ignore case
    {
      my $re = Regex->new("abc", "i");
      
      my $string = "ABC";
      my $match = $re->match($string);
      
      unless ($match) {
        return 0;
      }
    }

    {
      my $re = Regex->new("bc");
      
      my $string = "abcdbc";
      my $offset = 0;
      {
        my $match = $re->match($string, \$offset);
        
        unless ($match) {
          return 0;
        }
        
        unless ($offset == 3) {
          return 0;
        }
      }

      {
        my $match = $re->match($string, \$offset);
        
        unless ($match) {
          return 0;
        }
        
        unless ($offset == 6) {
          return 0;
        }
      }

      {
        my $match = $re->match($string, \$offset);
        
        if ($match) {
          return 0;
        }
      }
    }
    
    {
      my $re = Regex->new("bc");
      
      my $string = "abcdbc";
      my $offset = 0;
      
      my $match_count = 0;
      while ($re->match($string, \$offset)) {
        $match_count++;
      }
      
      unless ($match_count == 2) {
        return 0;
      }
      unless ($offset == 6) {
        return 0;
      }
    }

    {
      my $re = Regex->new("bc");
      
      my $string = copy "abcdbc";
      my $offset = 0;
      $re->replace((mutable string)$string, "BC");
      
      unless ($string eq "aBCdbc") {
        return 0;
      }
    }

    # '\b'
    {
      {
        my $re = Regex->new("\b");

        my $target = "12 34 56";
        my $match = $re->match($target);

        unless ($match) {
          return 0;
        }
      }

      {
        my $re = Regex->new("\b");
        my $target = copy "ab cde";
        $re->replace((mutable string)$target, "_");
        unless ($target eq "_ab cde") {
          return 0;
        }
      }

      {
        my $re = Regex->new("\b");
        my $target = copy "  k";
        $re->replace((mutable string)$target, "_");
        unless ($target eq "  _k") {
          return 0;
        }
      }

    }
    
    {
      my $string = copy "foo//bar///baz";
      Re->s((mutable string)$string, ["^/*|/+", "g"], "/");
      
      unless ($string eq "/foo/bar/baz") {
        return 0;
      }
    }
    
    return 1;
  }

  static method extra_url_escape : string ($input : string) {
    
    # URL escape
    my $regex = Regex->new("([^A-Za-z0-9\-\._~])");
    my $output = copy $input;
    $regex->replace_g((mutable string)$output, method : string ($re : Regex, $match : Regex::Match) {
      my $bytes = $match->cap1;
      
      my $escaped_char_buffer = StringBuffer->new;
      
      for (my $i = 0; $i < length $bytes; $i++) {
        my $byte = $bytes->[$i];
        my $hex_string = Format->sprintf("%%%02X", [(object)($byte & 0xFF)]);
        $escaped_char_buffer->push($hex_string);
      }
      
      my $escaped_char = $escaped_char_buffer->to_string;
      
      return $escaped_char;
    });
    
    return $output;
  }
  
  static method extra_url_unescape : string ($input : string) {
    
    # URL unescape
    my $regex = Regex->new("%([0-9a-fA-F]{2,2})");
    my $output = copy $input;
    $regex->replace_g((mutable string)$output, method : string ($re : Regex, $match : Regex::Match) {
      my $cap1 = $match->cap1;
      my $hex = Fn->hex($cap1);
      my $ch = (string)[(byte)$hex];
      return $ch;
    });
    
    return $output;
  }

  static method split : int () {
    {
      my $string = "foo  bar   baz";
      my $splited_strings = Regex->new("\s+")->split($string);
      unless (Array->equals_string($splited_strings, ["foo", "bar", "baz"])) {
        return 0;
      }
    }
    
    {
      my $string = "foo\\bar/baz";
      my $splited_strings = Regex->new("[/\\\\]")->split($string);
      unless (Array->equals_string($splited_strings, ["foo", "bar", "baz"])) {
        return 0;
      }
    }

    {
      my $string = "foo,bar,baz";
      my $splited_strings = Regex->new(",")->split($string);
      unless (Array->equals_string($splited_strings, ["foo", "bar", "baz"])) {
        return 0;
      }
    }
    
    {
      my $string = "foo,bar,";
      my $splited_strings = Regex->new(",")->split($string);
      unless (Array->equals_string($splited_strings, ["foo", "bar"])) {
        return 0;
      }
    }
    
    {
      my $string = ",foo,,bar,,";
      my $splited_strings = Regex->new(",")->split($string);
      unless (Array->equals_string($splited_strings, ["", "foo", "", "bar"])) {
        return 0;
      }
    }
    
    {
      my $string = "foo : bar : baz";
      my $splited_strings = Regex->new(" : ",)->split($string);
      unless (Array->equals_string($splited_strings, ["foo", "bar", "baz"])) {
        return 0;
      }
    }
    {
      my $string = "foo : bar : ";
      my $splited_strings = Regex->new(" : ",)->split($string);
      unless (Array->equals_string($splited_strings, ["foo", "bar"])) {
        return 0;
      }
    }
    {
      my $string = " : foo :  : bar :  : ";
      my $splited_strings = Regex->new(" : ",)->split($string);
      unless (Array->equals_string($splited_strings, ["", "foo", "", "bar"])) {
        return 0;
      }
    }
    {
      my $string = "foo---bar---baz";
      my $splited_strings = Regex->new("---",)->split($string);
      unless (Array->equals_string($splited_strings, ["foo", "bar", "baz"])) {
        return 0;
      }
    }
    {
      my $string = "foo---bar---";
      my $splited_strings = Regex->new("---",)->split($string);
      unless (Array->equals_string($splited_strings, ["foo", "bar"])) {
        return 0;
      }
    }
    {
      my $string = "---foo------bar------";
      my $splited_strings = Regex->new("---",)->split($string);
      unless (Array->equals_string($splited_strings, ["", "foo", "", "bar"])) {
        return 0;
      }
    }
    
    {
      my $string = "foo--!bar---baz";
      my $splited_strings = Regex->new("---",)->split($string);
      unless (Array->equals_string($splited_strings, ["foo--!bar", "baz"])) {
        return 0;
      }
    }

    {
      my $string = "foo,bar,baz";
      my $splited_strings = Regex->new(",")->split($string, -1);
      unless (Array->equals_string($splited_strings, ["foo", "bar", "baz"])) {
        return 0;
      }
    }
    {
      my $string = "foo,bar,baz";
      my $splited_strings = Regex->new(",")->split($string);
      unless (Array->equals_string($splited_strings, ["foo", "bar", "baz"])) {
        return 0;
      }
    }
    
    {
      my $string = "foo,bar,";
      my $splited_strings = Regex->new(",")->split($string, -1);
      unless (Array->equals_string($splited_strings, ["foo", "bar", ""])) {
        return 0;
      }
    }
    
    {
      my $string = ",foo,,bar,,";
      my $splited_strings = Regex->new(",")->split($string, -1);
      unless (Array->equals_string($splited_strings, ["", "foo", "", "bar", "", ""])) {
        return 0;
      }
    }
    
    {
      my $string = "foo : bar : baz";
      my $splited_strings = Regex->new(" : ",)->split($string, -1);
      unless (Array->equals_string($splited_strings, ["foo", "bar", "baz"])) {
        return 0;
      }
    }
    {
      my $string = "foo : bar : ";
      my $splited_strings = Regex->new(" : ",)->split($string, -1);
      unless (Array->equals_string($splited_strings, ["foo", "bar", ""])) {
        return 0;
      }
    }
    {
      my $string = " : foo :  : bar :  : ";
      my $splited_strings = Regex->new(" : ",)->split($string, -1);
      unless (Array->equals_string($splited_strings, ["", "foo", "", "bar", "", ""])) {
        return 0;
      }
    }
    
    {
      my $string = "foo---bar---baz";
      my $splited_strings = Regex->new("---",)->split($string, -1);
      unless (Array->equals_string($splited_strings, ["foo", "bar", "baz"])) {
        return 0;
      }
    }
    {
      my $string = "foo---bar---";
      my $splited_strings = Regex->new("---",)->split($string, -1);
      unless (Array->equals_string($splited_strings, ["foo", "bar", ""])) {
        return 0;
      }
    }
    {
      my $string = "---foo------bar------";
      my $splited_strings = Regex->new("---",)->split($string, -1);
      unless (Array->equals_string($splited_strings, ["", "foo", "", "bar", "", ""])) {
        return 0;
      }
    }
    
    {
      my $string = "foo--!bar---baz";
      my $splited_strings = Regex->new("---",)->split($string, -1);
      unless (Array->equals_string($splited_strings, ["foo--!bar", "baz"])) {
        return 0;
      }
    }
    
    {
      my $string = "foo,bar,baz";
      my $splited_strings = Regex->new(",")->split($string, 1);
      unless (Array->equals_string($splited_strings, ["foo,bar,baz"])) {
        return 0;
      }
    }
    
    {
      my $string = "foo,bar,baz";
      my $splited_strings = Regex->new(",")->split($string, 2);
      unless (Array->equals_string($splited_strings, ["foo", "bar,baz"])) {
        return 0;
      }
    }
    
    {
      my $string = "foo,bar,baz";
      my $splited_strings = Regex->new(",")->split($string, 3);
      unless (Array->equals_string($splited_strings, ["foo", "bar", "baz"])) {
        return 0;
      }
    }
    
    {
      my $string = "foo,bar,baz";
      my $splited_strings = Regex->new(",")->split($string, 4);
      unless (Array->equals_string($splited_strings, ["foo", "bar", "baz"])) {
        return 0;
      }
    }
    
    {
      my $string = "foo<cap1>bar<cap2>baz";
      my $splited_strings = Regex->new("(<.*?>)")->split($string);
      
      unless (Array->equals_string($splited_strings, ["foo", "<cap1>", "bar", "<cap2>", "baz"])) {
        return 0;
      }
    }
    
    # Exceptions
    {
      {
        my $sep = ",";
        my $string = (string)undef;
        my $limit = -1;
        eval {
          Regex->new($sep)->split($string, $limit);
        };
        unless ($@) {
          return 0;
        }
      }
      
      
    }

    return 1;
  }
  
  static method match_extra : int () {

    # Match string
    {
      my $re = Regex->new("abc");
      my $target = copy "zabcz";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }
    
    # Match same string
    {
      my $re = Regex->new("abc");
      my $target = copy "abc";
      
      my $match = $re->match($target);
      
      unless ($match) {
        return 0;
      }
    }

    # ignore case
    {
      {
        my $re = Regex->new("abz", "i");
        my $target = copy "zABZz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }

      {
        my $re = Regex->new("ABZ", "i");
        my $target = copy "zabzz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
      
      {
        my $re = Regex->new("A[B-Z]{2,2}", "i");
        my $target = copy "zabzz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }

      {
        my $re = Regex->new("a[b-z]{2,2}", "i");
        my $target = copy "zABZz";
        
        my $match = $re->match($target);
        
        unless ($match) {
          return 0;
        }
      }
    }
    
    return 1;
  }
  
  static method match_extra_forward : int () {
    
    # Not Match string
    {
      my $re = Regex->new("abc");
      my $target = copy "zabcz";
      
      my $match = (my $offset = 2, $re->match($target, \$offset));
      
      if ($match) {
        return 0;
      }
      
      unless ($offset == 2) {
        return 0;
      }
    }
    
    # Match string
    {
      my $re = Regex->new("abc");
      my $target = copy "zabcz";
      
      my $match = (my $offset = 1, $re->match($target, \$offset));
      
      unless ($match) {
        return 0;
      }
      
      unless ($offset == 4) {
        return 0;
      }
    }
    
    return 1;
  }
  
  static method replace_extra : int () {
    # Replace
    {
      my $re = Regex->new("abc");
      my $target = copy "ppzabcz";
      my $replace_info = $re->replace((mutable string)$target, "ABC");
      
      unless ($replace_info) {
        return 0;
      }
      
      unless ($target eq "ppzABCz") {
        return 0;
      }
    }
    
    # Not Replace
    {
      my $re = Regex->new("abd");
      my $target = copy "ppzabcz";
      my $replace_info = $re->replace((mutable string)$target, "ABC");
      
      if ($replace_info) {
        return 0;
      }
      
    }
    
    # Replace offset
    {
      my $re = Regex->new("abc");
      my $target = copy "ppzabczabczabcz";
      my $offset = 6;
      my $replace_info = $re->replace((mutable string)$target, "ABC", \$offset);
      
      unless ($replace_info) {
        return 0;
      }
      
      unless ($target eq "ppzabczABCzabcz") {
        return 0;
      }
    }
    
    # Replace - capture
    {
      my $re = Regex->new("^(\d+)a(\d+)$");
      my $target = copy "123a456";
      my $offset = 0;
      my $length = -1;
      my $replace_info = $re->replace((mutable string)$target, "", \$offset, $length);
      
      unless ($replace_info) {
        return 0;
      }
      
      unless ($replace_info->match->cap1 eq "123") {
        return 0;
      }
      
      unless ($replace_info->match->cap2 eq "456") {
        return 0;
      }
      
      unless ($target eq "") {
        return 0;
      }
    }
    
    return 1;
  }
  
  static method replace_extra_g : int () {
    # Replace all
    {
      my $re = Regex->new("abc");
      my $target = copy "ppzabczabcz";
      my $offset = 0;
      my $length = -1;
      my $replace_info = $re->replace_g((mutable string)$target, "ABC", \$offset, $length);
      
      unless ($replace_info->replaced_count == 2) {
        return 0;
      }
      
      unless ($target eq "ppzABCzABCz") {
        return 0;
      }
    }
    
    # Replace all offset
    {
      my $re = Regex->new("abc");
      my $target = copy "ppzabczabczabcz";
      my $offset = 6;
      my $length = -1;
      my $replace_info = $re->replace_g((mutable string)$target, "ABC", \$offset, $length);
      
      unless ($replace_info->replaced_count == 2) {
        return 0;
      }
      
      unless ($target eq "ppzabczABCzABCz") {
        return 0;
      }
    }
    
    # Replace all with number
    {
      my $re = Regex->new("a\d+b");
      my $target = copy "za123bz";
      my $offset = 0;
      my $length = -1;
      my $replace_info = $re->replace_g((mutable string)$target, "ABC", \$offset, $length);
      
      unless ($replace_info->replaced_count == 1) {
        return 0;
      }
      
      unless ($target eq "zABCz") {
        return 0;
      }
    }
    
    # Replace all - Not replace_g
    {
      my $re = Regex->new("a\d+b");
      my $target = copy "pppp";
      my $offset = 0;
      my $length = -1;
      my $replace_info = $re->replace_g((mutable string)$target, "ABC", \$offset, $length);
      
      if ($replace_info) {
        return 0;
      }
      
      unless ($target eq "pppp") {
        return 0;
      }
    }
    
    return 1;
  }
  
  static method m : int () {
    
    # Match string
    {
      my $re = "abc";
      my $target = copy "zabcz";
      
      my $match = Re->m($target, $re);
      
      unless ($match) {
        return 0;
      }
    }
    
    # Match string - cached
    {
      my $re = "abc";
      my $target = copy "zabcz";
      
      my $match = Re->m($target, $re);
      
      unless ($match) {
        return 0;
      }
    }
    
    # Match same string
    {
      my $re = "abc";
      my $target = copy "abc";
      
      my $match = Re->m($target, $re);
      
      unless ($match) {
        return 0;
      }
    }
    
    # ignore case
    {
      {
        my $re = "abz";
        my $flags = "i";
        my $target = copy "zABZz";
        
        my $match = Re->m($target, [$re, $flags]);
        
        unless ($match) {
          return 0;
        }
      }
      
      {
        my $re = "ABZ";
        my $flags = "i";
        my $target = copy "zabzz";
        
        my $match = Re->m($target, [$re, $flags]);
        
        unless ($match) {
          return 0;
        }
      }
      
      {
        my $re = "A[B-Z]{2,2}";
        my $flags = "i";
        my $target = copy "zabzz";
        my $match = Re->m($target, [$re, $flags]);
        
        unless ($match) {
          return 0;
        }
      }
      
      {
        my $re = "a[b-z]{2,2}";
        my $flags = "i";
        my $target = copy "zABZz";
        
        my $match = Re->m($target, [$re, $flags]);
        
        unless ($match) {
          return 0;
        }
      }
    }
    
    return 1;
  }
  
  static method s : int () {
    # Replace
    {
      my $re = "abc";
      my $target = copy "ppzabcz";
      my $replace_info = Re->s((mutable string)$target, $re, "ABC");
      
      unless ($replace_info) {
        return 0;
      }
      
      unless ($target eq "ppzABCz") {
        return 0;
      }
    }
    
    # Not Replace
    {
      my $re ="abd";
      my $target = copy "ppzabcz";
      my $replace_info = Re->s((mutable string)$target, $re, "ABC");
      
      if ($replace_info) {
        return 0;
      }
      
    }
    
    # Replace offset
    {
      my $re = "abc";
      my $target = copy "ppzabczabczabcz";
      my $offset = 6;
      my $replace_info = Re->s((mutable string)$target, $re, "ABC", \$offset);
      
      unless ($replace_info) {
        return 0;
      }
      
      unless ($target eq "ppzabczABCzabcz") {
        return 0;
      }
    }
    
    # Replace - capture
    {
      my $re = "^(\d+)a(\d+)$";
      my $target = copy "123a456";
      my $offset = 0;
      my $length = -1;
      my $replace_info = Re->s((mutable string)$target, $re, "", \$offset, $length);
      
      unless ($replace_info) {
        return 0;
      }
      
      unless ($replace_info->match->cap1 eq "123") {
        return 0;
      }
      
      unless ($replace_info->match->cap2 eq "456") {
        return 0;
      }
      
      unless ($target eq "") {
        return 0;
      }
    }
    
    # Replace
    {
      my $re = "abc";
      my $target = (mutable string)copy "ppzabcz";
      my $replace_info = Re->s($target, $re, "ABC");
      
      unless ($replace_info) {
        return 0;
      }
      
      unless ($target eq "ppzABCz") {
        return 0;
      }
    }
    
    return 1;
  }
  
  static method s_g : int () {
    
    # Replace all
    {
      my $re = "abc";
      my $target = copy "ppzabczabcz";
      my $offset = 0;
      my $length = -1;
      my $replace_info = Re->s((mutable string)$target, [$re, "g"], "ABC", \$offset, $length);
      
      unless ($replace_info->replaced_count == 2) {
        return 0;
      }
      
      unless ($target eq "ppzABCzABCz") {
        return 0;
      }
    }
    
    # Replace all offset
    {
      my $re = "abc";
      my $target = copy "ppzabczabczabcz";
      my $offset = 6;
      my $length = -1;
      my $replace_info = Re->s((mutable string)$target, [$re, "g"], "ABC", \$offset, $length);
      
      unless ($replace_info->replaced_count == 2) {
        return 0;
      }
      
      unless ($target eq "ppzabczABCzABCz") {
        return 0;
      }
    }
    
    # Replace all with number
    {
      my $re = "a\d+b";
      my $target = copy "za123bz";
      my $offset = 0;
      my $length = -1;
      my $replace_info = Re->s((mutable string)$target, [$re, "g"], "ABC", \$offset, $length);
      
      unless ($replace_info->replaced_count == 1) {
        return 0;
      }
      
      unless ($target eq "zABCz") {
        return 0;
      }
    }
    
    # Replace all - Not replace
    {
      my $re = "a\d+b";
      my $target = copy "pppp";
      my $offset = 0;
      my $length = -1;
      my $replace_info = Re->s((mutable string)$target, [$re, "g"], "ABC", \$offset, $length);
      
      if ($replace_info) {
        return 0;
      }
      
      unless ($target eq "pppp") {
        return 0;
      }
    }
    
    return 1;
  }
  
  static method re_split : int () {
    {
      my $string = "foo  bar   baz";
      my $splited_strings = Re->split("\s+", $string);
      unless (Array->equals_string($splited_strings, ["foo", "bar", "baz"])) {
        return 0;
      }
    }
    
    {
      my $string = "fooPbarPbaz";
      my $splited_strings = Re->split(["p", "i"], $string);
      unless (Array->equals_string($splited_strings, ["foo", "bar", "baz"])) {
        return 0;
      }
    }
    
    {
      my $string = "foo,bar,baz";
      my $splited_strings = Re->split(",", $string, 2);
      unless (Array->equals_string($splited_strings, ["foo", "bar,baz"])) {
        return 0;
      }
    }
    
    return 1;
  }
  
  static method extra_issue9 : int () {
    
    my $path = copy "";
    
    # xx////xx  -> xx/xx
    Re->s((mutable string)$path, ["/{2,}", "g"], "/");
  }

}
