LEVIATHAN vd52e79c4 · d52e79c486

Standard Library · regex

struct Group

One capture group of a match: whether it took part, and where and what it matched.

since 0.1.0-alpha.1linuxwindowswasm

Overview

A group that did not take part in a successful match (for example the arm of an alternation that was not taken) is a normal state, not an error: matched is false, index is -1, length is 0 and value is "".

Examples

A group that did not take part

use io::console;
use regex;
use regex::Group;
use regex::Match;

Match? n = regex::find("b", r"(a+)|(b+)");
if (n != None) {
    Group g1 = n.group(1);
    Group g2 = n.group(2);
    console.writeln("${g1.matched} ${g1.index} ${g1.length} [${g1.value}]");
    console.writeln("${g2.matched} ${g2.index} ${g2.length} [${g2.value}]");
}
false -1 0 []
true 0 1 [b]

Fields

index

int index

Byte offset of the group text in the searched string, or -1 when the group did not take part.

length

int length

Length of the group text in bytes, or 0 when the group did not take part.

matched

bool matched

true when the group took part in the match.

value

string value

The text the group matched, or "" when the group did not take part.

See also

  • Match — A successful match: where it is, what it matched, and its capture groups.