Open utterances-bot opened 4 years ago
No named groups in Haxe?
@sianahoret No, they are not supported consistently across our targets.
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 :(
That can probably be fixed, could you create an issue about it please?
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