HaxeFoundation / HaxeFoundation/haxe

clarify EReg.matched spec regarding capture groups

Open
#9,250 3 comments 0 reactions 0 assignees View on GitHub
documentation
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

So currently the doc for `EReg.matched` says this:

> The index `n` corresponds to the n-th set of parentheses in the pattern
of `this` EReg. If no such sub-group exists, the result is unspecified.

But it's not immediately clear what "no such sub-group exists" means exactly. I assume it means that the group was not defined in the regex. But it's a bit confusing in case the group _was_ defined but was not matched.

I.e. is it safe to rely on the following to consistently trace an empty string?

```haxe
var r = ~/(a)?b/;
if (r.match("b")) {
trace(r.matched(1));
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.