[haXe] haXe regexp and subexpressions

Michael Pliskin pl at tepkom.ru
Thu Apr 5 15:33:17 CEST 2007


Hello list,

  I am trying to port a perl code to haxe now, and found a problem -
  I don't find any easy way to re-use once compiled regexps. For
  instance, consider the following in perl:

  my $text           = qr/[^\x0A\x0D]/;

  my $quoted_pair    = qr/\\$text/;

  How would I re-write this in haxe? I can go dumb and do like
  var text = "[^" + Std.chr(0x0A) + Std.chr(0x0D) + "]";
  var quoted_pair = "\\" + text;
  var reg = new EReg(quoted_pair, "");
  
  but it is
    a) relatively cumbersome
    b) not that efficient - need to compile sub-regexps more than once
       if re-using many times
    c) not sure if it is semantically equivalent. I think (but not
       sure, not that good in Perl/regexps) in Perl
       my $r1 = qr/a*b/;
       my $r2 = qr/$r1*/;
       would be different from
       my $r3 = qr/a*b*/;
       as the first one has implicit grouping.

  So - does anybody know a way to overcome the problem?

-- 
Best regards,
 Michael                          mailto:pl at tepkom.ru




More information about the Haxe mailing list