HaxeFoundation / haxe.org-comments

Repository to collect comments of our haxe.org websites
2 stars 2 forks source link

[haxe.org/manual] Groups #50

Open utterances-bot opened 4 years ago

utterances-bot commented 4 years ago

Groups - Haxe - The Cross-platform Toolkit

Haxe is an open source toolkit based on a modern, high level, strictly typed programming language.

https://haxe.org/manual/std-regex-groups.html

sianahoret commented 4 years ago

No named groups in Haxe?

Aurel300 commented 4 years ago

@sianahoret No, they are not supported consistently across our targets.

sianahoret commented 4 years ago

Heh, I've just found that even if I use the native javascript's RegExp (from js.lib.RegExp), I still can't use the named capture groups in a type-safe manner:

import js.lib.RegExp;

class TestRegexp {
  static public function main(): Void {
    var s = "Haxe EReg class does not support named capture groups";`
    var re = new RegExp("(?<className>\\S*)\\s*class");
    var res = re.exec(s);

    // Compiler gives "Null<js.lib.RegExpMatch> has no field groups" error
    // unless I prefix the line containing `res.groups` with `untyped`.
    // I believe - because extern class RegExpMatch (https://github.com/HaxeFoundation/haxe/blob/4.0.5/std/js/lib/RegExp.hx)
    // misses that...
    trace('Regular expressions in Haxe are implemented by ${res.groups.className} class.');
  }
}

Sadly :(

nadako commented 4 years ago

That can probably be fixed, could you create an issue about it please?

sianahoret commented 4 years ago

https://github.com/HaxeFoundation/haxe/issues/9300